简体   繁体   中英

Unable to click on dropdown made by <div> using Selenium WebDriver

HTML code

<div qxselectable="off" >
<div qxselectable="off" >
<div tabindex="1" qxselectable="off" >
<div tabindex="1" qxselectable="off" >
<div style="overflow: hidden; >Discrepancy Type*</div>
<div class="qx-input-required" tabindex="7" ">    
<input class="qx-abstract-field qx-placeholder-color" >
//On Below button there is one dropdown button on which i want to click but i cannot 
<div class="qx-button" qxselectable="off" >
<div qxselectable="off" qxanonymous="true" ></div>
</div>
</div>
</div>
<div tabindex="1" qxselectable="off" >
</div>
</div>
<div class="qx-outSet" qxse..

Java Code

WebElement element = wd.findElement(By.className("qx-input-required"));
Actions actions = new Actions(wd);
actions.moveToElement(element).click().perform();
wd.findElement(By.xpath(".//*[@id='demindoRoot']/div[3]/div[2]/div[1]/div/div[2]/div[2]/div/div")).click(); // link through which i try to click 
Thread.sleep(1000);

I also tried with below mention code

wd.findElement(By.xpath("//div[@class='qx-button'"));

在此处输入图片说明

Error :

Unable to locate element:

action.moveToElement(element).moveToElement(driver.findElement(By.Xpath(<Your path here>))).click().build().perform();

This performs the action more like a user would. They user first navigates to the menu, opens it, then navigates to the element they wish to click. Check out this question for more details: https://stackoverflow.com/a/17294390/3537915

WebDriverWait wait = new WebDriverWait(d, 10);
    WebElement val = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath()));
    val.click();


    for(int i=0;i<=100;i++)
    {

        String value=val.getText();
        System.out.println("value is = "+value);
        String value1 = "Your dropdown value";
        if(value.equalsIgnoreCase(value1))
        {
            System.out.println("Got your dropdown value ");
            a.sendKeys(Keys.ENTER).build().perform();
            break;
        }
        a.sendKeys(Keys.DOWN,Keys.DOWN).build().perform();
        Thread.sleep(3000);
        a.sendKeys(Keys.ENTER).build().perform();
    }

xpath should be your dropdown box not of your dropdown value.

Basically when we works with anywebapplication which developed using any javascript freamwork at that w cannot get any proper element to interact. We have to work with lots of and . So while selecting any value from dropdown we have to use sendkeys. OR simple type single character and select value from suggestion list. Above two solution works for me .

Thanks -Dhaval

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