HTML代码
<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代码
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);
我也试过下面提到的代码
wd.findElement(By.xpath("//div[@class='qx-button'"));
错误:
无法找到元素:
答案 0 :(得分:1)
action.moveToElement(element).moveToElement(driver.findElement(By.Xpath(<Your path here>))).click().build().perform();
这更像用户执行操作。用户首先导航到菜单,打开它,然后导航到他们想要点击的元素。查看此问题以获取更多详细信息: https://stackoverflow.com/a/17294390/3537915
答案 1 :(得分:0)
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应该是您的下拉框而不是您的下拉值。
答案 2 :(得分:0)
基本上,当我们使用任何javascript freamwork开发的anywebapplication时,w无法获得任何适当的元素进行交互。 我们必须和很多人一起工作。 因此,当从下拉列表中选择任何值时,我们必须使用sendkeys。 或简单类型单个字符并从建议列表中选择值。 以上两种解决方案对我有用。
由于 -Dhaval