![](/img/trans.png)
[英]How to get the value inside a div tag in a table using selenium webdriver
[英]How to get the value of div tag
如何從中獲取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>
嘗試以下代碼獲取MY_TROUBLE_TWO
的值
注意:使用relative xpath
而不是使用absolute xpath
relative xpath
。
說明:在元素之前先等待,為了等待,我使用了explicit wait
方法。 等待之后,使用帶有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.