如何从中获取MY_TROUBLE_TWO
并点击?
我已经尝试了下面提到的代码,但它没有为我工作。
尝试代码1)
WebElement element = driver.findElement(By.xpath(".//div[7]/div/div/div/div/div/div/div[2]/div[@class='dx-item-content dx-list-item-content']"));
element.click();
尝试代码2)
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//div[7]/div/div/div/div/div/div/div[2]/div[@class='dx-item-content dx-list-item-content']"))).click();
尝试代码3)
Select select = new Select(driver.findElement(By.xpath(".//xpath_to_item")));
select.selectByVisibleText("MY_TROUBLE_TWO");
我的html
代码如下:
<div class="dx-scrollview-content" onclick="void(0)">
<div id="50d24777-593c-7626-d924-2a3db0e72e89" class="dx-item dx-list-item dx-list-item-selected dx-state-focused" role="option" aria-selected="true" style="">
<div class="dx-item-content dx-list-item-content">MY_TROUBLE_ONE</div>
</div>
<div class="dx-item dx-list-item" role="option" aria-selected="false">
<div class="dx-item-content dx-list-item-content">MY_TROUBLE_TWO</div>
</div>
</div>
答案 0 :(得分:1)
请尝试以下代码获取MY_TROUBLE_TWO
注意:使用absolute xpath
而不是relative xpath
。
说明:在转到元素前等待一段时间,等待我使用explicit wait
方法。使用带有text
标记的div
方法等待查找元素后获取元素。
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//div[contains(text(), 'MY_TROUBLE_TWO')]")))).click();