Selenium無法找到元素。 我正在嘗試查找帶有PageHeader_logourl 的ID但它正在拋出無法找到具有xpath表達式的元素。Selenium無法找到元素
難道我做錯什麼
下面是HTML代碼
<DIV id="page" class="page">
<DIV id="wrapper" class="wrapper">
<DIV id="header" class="header">
<TABLE width="100%" height="40" cellspacing="0" cellpadding="0" border="0" ID="Table2">
<TR>
<TD>
<TABLE height="40" cellspacing="0" cellpadding="0" border="0" ID="Table3">
<TR>
<TD><a href="http://www.scania.com" id="PageHeader_logoUrl" tabIndex="-1" target="_blank"><span id="HeaderLogoImage"></span></a></TD>
<TD valign="middle"><label id="PageHeader_lblProjectName" class="projectname">Scania Trucks – SSS 4 TestR1</label></TD>
這裏是我的硒代碼快照:
driver.findElement(By.xpath("//input[@name='UserNameInputText']")).sendKeys(username);
driver.findElement(By.xpath("//input[@name='Brand']")).sendKeys(password);
driver.findElement(By.xpath("//input[@name='CmdLogin']")).click();
Assert.assertTrue(isuserloggedin(),"Login failed");
}
public boolean isuserloggedin()
{
boolean flag = false;
if (!driver.findElements(By.id("Cancel")).isEmpty() ||
driver.findElement(By.xpath("//a[@id=['PageHeader_logoUrl']")).isDisplayed());
{
flag = true;
}
return flag;
爲什麼不使用'findelement(By.id('PageHeader_logoUrl')'? – RemcoW