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天,但我找不到解决方案。
答案 0 :(得分:0)
以下是您需要做的一些更改:
使用Selenium 3.4.0以及最新的gecko驱动程序0.16&amp; 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();
}
如果这有助于您,请告诉我。