【问题标题】:Selenium Webdriver click not workingSelenium Webdriver 单击不起作用
【发布时间】:2014-01-12 08:42:42
【问题描述】:

我正在尝试使用 selenium webdriver 来自动化我的测试 我正在使用 selenium 2.39.0 和 firefox 26.0 我正在尝试一个简单的点击示例,但它失败了 该元素被选中是因为所选元素文本上的 sysout 给出了“创建帐户”。但它无法单击按钮

 WebDriver driver = new FirefoxDriver();
driver.get("http://en.wikipedia.org/wiki/Main_Page");
System.out.println(driver.findElement(By.id("pt-createaccount")).getText());
driver.findElement(By.id("pt-createaccount")).click();
assertEquals("Create account - Wikipedia, the free encyclopedia", driver.getTitle());
driver.quit();

感谢任何帮助

尝试了以下所有方法 得到了 selenium google 组的回复,这很有效

请打开系统显示设置,确保字体大小设置为 100%,见附件截图。 https://code.google.com/p/selenium/issues/detail?id=6756

【问题讨论】:

  • pt-createaccount 不是链接,而是li。我可以想象这可能是 Selenium 的问题。你试过用driver.findElement(By.linkText("Create account")).click();吗?

标签: java selenium-webdriver


【解决方案1】:
public class Wiki

{

     @Test
     public void createAccount() throws InterruptedException
     {
     WebDriver driver = new FirefoxDriver();
     WebDriverWait wait=new WebDriverWait(driver,60);
     driver.get("http://en.wikipedia.org/wiki/Main_Page");
     driver.findElement(By.linkText("Create account")).click();
     wait.until(ExpectedConditions.titleContains("Create account - Wikipedia, the free encyclopedia"));
     Assert.assertEquals("Create account - Wikipedia, the free encyclopedia",driver.getTitle());
     driver.quit();
     }

}

【讨论】:

    【解决方案2】:

    你需要点击“a”元素:

    IWebElement createAccountLink = driver.findElement(By.id("pt-createaccount")).FindElement(By.TagName("a"));  
    createAccountLink.Click();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-18
      • 2019-05-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多