[英]java: Selenium Webdriver: how to get text from element which has style 'display: none'
我有一个webelement,它在鼠标悬停时显示一些文本(不是工具提示),html代码是
<div class="total-discout-outer" style="display: block;">
<div class="total-discout-show">
<div class="discount-arrow-top"></div>
<div style="line-height:12px;font-size:13px;"> Promo Applied: (-) Rs 2</div>
</div>
</div>
现在,只要将鼠标移到此处或此处一点,文本就会消失,因为它是html
<div class="total-discout-outer" style="display: none;">
<div class="total-discout-show">
<div class="discount-arrow-top"></div>
<div style="line-height:12px;font-size:13px;"> Promo Applied: (-) Rs 2</div>
</div>
</div>
我试图为其生成xpath,并使用XPathChecker对其进行了检查,它工作正常,但与硒给了NoSuchElement异常
我使用的xpath是
//div[contains(@style,'display: none')]//div[contains(text(),'Promo')]
我也尝试过
Actions builder = new Actions(driver);
builder.moveToElement(driver.findElement(By.xpath("//div[@class='discounted-price']"))).build().perform();
System.out.println(driver.findElement(By.className("total-discount-show")).getText());
“打折价格”是悬停时显示促销文字的Web元素,但上面也给出了NoSuchElementException。 现在我该如何从中获取文本。
不确定是否有帮助,但是在该div上使用.getAttribute("style")
,您将获得字符串形式的值!
在我的情况下,Js代码正在运行,请看看
public static string GetValueFromele(IWebElement element, IWebDriver Driver)
{
IJavaScriptExecutor javaScriptExecutor = (IJavaScriptExecutor)Driver;
string value = javaScriptExecutor.ExecuteScript("return arguments[0].innerHTML", element) as string;
return value;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.