我正在尝试使用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
答案 0 :(得分:1)
您需要点击“a”元素:
IWebElement createAccountLink = driver.findElement(By.id("pt-createaccount")).FindElement(By.TagName("a"));
createAccountLink.Click();
答案 1 :(得分:0)
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();
}
}