[英]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.