[英]How to get the value of div tag
How can I get MY_TROUBLE_TWO
from it and click? 如何从中获取
MY_TROUBLE_TWO
并单击?
I have tried below mentioned code, but it didn't get work for me. 我已经尝试过下面提到的代码,但是对我来说没有用。
Tried code 1) 尝试代码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();
Tried code 2) 尝试代码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();
Tried code 3) 尝试过的代码3)
Select select = new Select(driver.findElement(By.xpath(".//xpath_to_item")));
select.selectByVisibleText("MY_TROUBLE_TWO");
My html
code as below: 我的
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>
Try this below code to get the value of MY_TROUBLE_TWO
尝试以下代码获取
MY_TROUBLE_TWO
的值
Note: Instead of using an absolute xpath
, Use relative xpath
. 注意:使用
relative xpath
而不是使用absolute xpath
relative xpath
。
Explanation: Put some wait before going to the element, For wait I have used explicit wait
method. 说明:在元素之前先等待,为了等待,我使用了
explicit wait
方法。 After wait find element using text
method with div
tag to get the element. 等待之后,使用带有
div
标签的text
方法查找元素以获取元素。
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//div[contains(text(), 'MY_TROUBLE_TWO')]")))).click();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.