[英]Unable to locate elements through selenium webdriver
HTML代码
<div id="all_transactions_for_account">
<table class="table table-condensed table-hover">
<thead>
<tr>
<th>Date</th>
<th>Description</th>
<th>Deposit</th>
<th>Withdrawal</th>
</tr>
</thead>
<tbody>
<tr>
<td>2012-09-06</td>
<td>ONLINE TRANSFER REF #UKKSDRQG6L</td>
<td>984.3</td>
<td></td>
</tr>
<tr>
<td>2012-09-05</td>
<td>OFFICE SUPPLY</td>
<td></td>
<td>50</td>
</tr>
<tr>
<td>2012-09-01</td>
<td>ONLINE TRANSFER REF #UKKSDRQG6L</td>
<td>1000</td>
<td></td>
</tr>
</tbody>
</table>
Java代码
public class Sample {
@Test
public void sampleMethod() throws InterruptedException
{
WebDriver driver;
driver= new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://zero.webappsecurity.com/login.html");
driver.findElement(By.id("user_login")).sendKeys("username");
driver.findElement(By.id("user_password")).sendKeys("password");
driver.findElement(By.name("submit")).click();
driver.findElement(By.linkText("Savings")).click();
WebElement e =driver.findElement(By.xpath(".//*[@id='all_transactions_for_account']/table/tbody/tr[2]/td[2]"));
System.out.println(e.getText());
}
}
不仅是单个元素,我也无法在此页面中找到任何元素。 参照画面
因此,请帮助我,我花了超过2天的时间,但找不到解决方案。
这是您需要做的一些更改:
要与Selenium 3.4.0以及最新的gecko驱动程序0.16和Mozila Firefox 53.0一起使用,您需要下载gecko驱动程序并保存。 在System.setProperty
提及壁虎驱动程序的绝对位置
最后,您的代码将如下所示:
@Test
public void sampleMethod()
{
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
WebDriver driver= new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://zero.webappsecurity.com/login.html");
driver.findElement(By.id("user_login")).sendKeys("username");
driver.findElement(By.id("user_password")).sendKeys("password");
driver.findElement(By.xpath("//input[@name='submit']")).click();
}
让我知道这是否对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.