2017-04-24 69 views
-2

在给Xpath登录后,当我通过硒测试脚本时,无法点击登录按钮。 情景 - •通过提供用户名和密码登录到应用程序。执行测试脚本时无法使用硒点击登录按钮

public class Myclass { 

    public static void main(String[] args) throws IOException, InterruptedException { 
    System.setProperty("webdriver.gecko.driver","C:\\Users\\karokiaswamy\\Documents\\Selenium_installation\\geckodriver-v0.15.0-win64\\geckodriver.exe"); 
    WebDriver driver = new FirefoxDriver(); 
    Runtime.getRuntime().exec("c:\\autoit\\HandleAuth.exe"); 
    driver.get("Application URL"); 
    //Runtime.getRuntime().exec("C:\\autoit\\HandleAuth.exe"); 
    Thread.sleep(1000); 
    driver.get("Application URL"); 
    driver.findElement(By.xpath(".//*[@id='siteLoginTab']/form/table/tbody/tr[1]/td[1]/input")).clear(); 
    driver.findElement(By.xpath(".//*[@id='siteLoginTab']/form/table/tbody/tr[1]/td[1]/input")).sendKeys("testtrack"); 
    driver.findElement(By.xpath(".//*[@id='siteLoginTab']/form/table/tbody/tr[1]/td[2]/input")).clear(); 
    driver.findElement(By.xpath(".//*[@id='siteLoginTab']/form/table/tbody/tr[1]/td[2]/input")).sendKeys("password01"); 
    driver.findElement(By.xpath(".//*[@id='siteLoginTab']/form/table/tbody/tr[1]/td[3]/button")).clear(); 
    driver.findElement(By.xpath(".//*[@id='siteLoginTab']/form/table/tbody/tr[1]/td[2]/input")).sendKeys(" "); 
    driver.findElement(By.xpath("///button[@class ='btnSmall btnGreen']")).click(); 
    //driver.findElement(By.xpath(".//*[@id='siteLoginTab']/form/table/tbody/tr[1]/td[3]/button")).click() 
    } 
} 
+0

复制您的登录页面的HTML,如果可能的 –

+0

你能否提供更多的信息:1。什么是你通过'调用Runtime.getRuntime()做的exec(“C: \\ autoit \\ HandleAuth.exe“);'? 2.你能为该网站提供有效的凭据吗? – DebanjanB

+0

@ venkatasiva - Runtime.getRuntime().exe(“c:\\ autoit \\ HandleAuth.exe”)用于在导航到应用程序之前为Authentication alert提供用户名和密码。 –

回答

0

如果我理解你,你点击登录按钮后会得到一个异常。 如果你做,你可以用JavaScript点击如下:

JavascriptExecutor js = (JavascriptExecutor)driver; 
js.executeScript("arguments[0].click()", element);