0

我有一个 web 元素,它在鼠标悬停时显示一些文本(它不是工具提示),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>

现在只要鼠标在这里或那里移动一点,文本就会消失,因为它是

<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 检查它工作正常,但使用 selenium 它给出 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。现在我如何从中获取文本。

4

2 回答 2

0

不确定它是否有帮助,但.getAttribute("style")在那个 div 上,你会得到字符串的值!

于 2014-09-18T07:15:20.723 回答
0

就我而言,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;
    }
于 2019-10-16T06:31:04.340 回答