【发布时间】:2018-08-07 12:06:27
【问题描述】:
嗨,我正在学习硒。我正在尝试从 FreeCrm.com 的索引页面获取用户名的 geText(),我的 xpath 从萤火虫中是正确的。但得到NoSuchElementExceptopn。
网址:https://www.freecrm.com 我的代码:
@Test(description="verify the account holder name displaying correctly or not")
public void AccHolderName() {
driver=new FirefoxDriver();
driver.get("https://www.freecrm.com/index.html");
driver.findElement(By.name("username")).sendKeys("xxxxx");
driver.findElement(By.name("password")).sendKeys("xxxx");
driver.findElement(By.xpath("//input[@class='btn btn-small']")).click();
String AccName=driver.findElement(By.xpath("//td[@class='headertable']//table//tbody//td[@class='headertext' and @align='left']")).getText().trim();
System.out.println(AccName);
错误:无法定位元素:
{"method":"xpath","selector":"//td[@class='headertable']//table//tbody//td[@class='headertext' and @align='left']"}
请帮我写代码
【问题讨论】:
-
不要共享凭据。而是发布相关的html。
-
您要从 DOM 中读取的项目可能不会在呈现基本页面后呈现,我的意思是它可能会通过 AJAX 呈现,因此您需要等到元素在页面
标签: java eclipse selenium selenium-webdriver