【问题标题】:Getting hover text with selenium in java在java中使用selenium获取悬停文本
【发布时间】:2012-05-25 20:36:03
【问题描述】:

我试图弄清楚如何从http://www.walmart.com/browse/TV-Video/TVs/_/N-96v3? 之类的页面获取产品可用性文本 (一旦选择了商店)我选择了 76574 作为我的邮政编码,然后转到“在我的商店”标签

我现在的代码是

WebElement hoverElement = driver.findElement(By.xpath(".//*[@id='Body_15992428']/span"));
WebElement hidden = driver.findElement(By.xpath(".//*[@id='slapInfo_NoVariant_15992428']/div"));
Actions builder = new Actions(driver);    
builder.clickAndHold(hoverElement).build().perform();
System.out.println(hidden.getText());

**编辑:我尝试了profile.setEnableNativeEvents(false);,文本现在显示在自动浏览器窗口中。我仍然无法得到我想要的文字。它不会抛出异常,只显示什么,因为驱动程序认为它仍然隐藏。有谁知道如何解决这个问题?

我不断收到

Exception in thread "main" org.openqa.selenium.InvalidElementStateException: Cannot perform native interaction: Could not load native events component.

即使在我这样做之后

 profile.setEnableNativeEvents(true); 

有没有其他方法可以获取隐藏文本,或者我在这里做错了什么?

另外,当我用 firebug 检查代码时,我看到有这段代码

<script type="text/javascript"> WALMART.$(document).ready(function(){ WALMART.$('#Body_15992428').hover(function(){ WALMART.$('#SeeStoreAvailBubble').wmBubble('update',WALMART.$('#bubbleMsgUpdate_15992428').html()); }); }); </script>

我真的不知道如何直接使用 javascript 来做事,但是有什么方法可以使用 javascript 执行器直接从其中获取消息文本?

【问题讨论】:

    标签: java javascript selenium webdriver


    【解决方案1】:

    获取页面内对象悬停文本的唯一方法是使用:

    webdriver.getattribute("Htmltag","alt text" );
    

    如果您需要任何帮助,请大声告诉我。

    【讨论】:

      猜你喜欢
      • 2016-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-14
      • 2012-07-22
      • 2022-11-01
      相关资源
      最近更新 更多