我UnexpectedTagNameException
获得cssSelector
。下面是HTML和java的代码片段
<table cellspacing="0" cellpadding="0" border="0" class="puMB">
<tbody><tr><td valign="center">
<div class="popupMenuButton">
<a id="_a9sizb" bh="PML" _mid="_op49pd" class="awmenuLink" style="text-decoration:none" href="#">
<nobr>
lucky
<img width="15" height="17" align="absmiddle" border="0" style="margin-bottom:1px;" src="/EasyCare-2.0/AribaWeb/ad/content/AWXDebugResourceActions/13/en_US/widg/arrowcolor.gif" alt=""></nobr></a></div></td></tr></tbody></table>
driverWait = new WebDriverWait(driver, 1000);
public WebElement waitByCSSSelector(String locator) {
return driverWait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(locator)));
}
WebElement dropDownListBox1 = waitById("_a9sizb");
Select clickThis1 = new Select(dropDownListBox1);
clickThis1.selectByIndex(5);
waitByCSSSelector("//*[@id='_a9sizb']").click();
Exception in thread "main" org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "a"
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:30'
System info: host: 'Sudhir', ip: '192.168.250.16', os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2', java.version: '1.7.0_51'
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.Select.<init>(Select.java:46)
at ui.UIRegisterPatient.setCharityAmount(UIRegisterPatient.java:151)
at tc.TCRegistrationNewEmerPatient.setCharityAmountForEmer(TCRegistrationNewEmerPatient.java:129)
at tc.TCRegistrationNewEmerPatient.setNewPrimayPatientDetails(TCRegistrationNewEmerPatient.java:32)
at tc.StartAutmation.main(StartAutmation.java:17)
当我尝试使用以下代码时
waitByCSSSelector("#_a9sizb > nobr > img").click();
该应用程序没有回复。
任何帮助都非常值得赞赏。如果已经讨论过,请道歉。
答案 0 :(得分:0)
错误在此字符串中:
Select clickThis1 = new Select(dropDownListBox1);
应选择“选择”类型,但不应为您提供的链接<a id="_a9sizb...
。正如我们从文档中看到的那样:
班级选择
为SELECT标记建模,提供帮助方法来选择和取消选择 选项。