简体   繁体   中英

Selenium: UnexpectedTagNameException for cssSelector in Java

I am getting UnexpectedTagNameException for cssSelector . Below is the piece of code for HTML and 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) 

When I try to use the following code

waitByCSSSelector("#_a9sizb > nobr > img").click();

There is no response from the application.

Any help is highly appreciable. Apologies if this has already been discussed.

The error is within this string: Select clickThis1 = new Select(dropDownListBox1);

"Select" type should be select, but not a link as you giving it <a id="_a9sizb... . As we see from documentation:

Class Select

Models a SELECT tag, providing helper methods to select and deselect options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM