0

我试图弄清楚如何从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); 

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

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

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

我真的不知道如何直接使用 javascript 做事,但有没有办法直接从 javascript 执行程序中获取消息文本?

4

1 回答 1

0

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

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

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

于 2012-05-30T21:12:01.727 回答