执行测试脚本时无法使用selenium单击“登录”按钮

时间:2017-04-24 11:03:57

标签: java xpath selenium-webdriver automated-tests

在为登录提供Xpath之后,当我通过selenium测试脚本时,无法单击“登录”按钮。 场景 - •通过提供用户名和密码登录应用程序。

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()
  }
}

1 个答案:

答案 0 :(得分:0)

如果我了解你,点击登录按钮后会出现异常。 如果你这样做,你可以点击javascript为:

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