简体   繁体   English

如何使用Java来解析Selenium Webdriver中所有元素的网页,该网页会定期连续刷新4秒钟?

[英]How to parse all the elements in Selenium Webdriver using Java for a webpage which is continously refreshing for 4 seconds periodically?

I am trying to find some elements, from a web page which is continuously refreshing for 4 seconds periodically. 我正在尝试从一个网页中查找一些元素,该网页会定期不断刷新4秒。 So when I am trying to detect some of the page elements after parsing the web page,it is throwing exception as : 因此,当我在解析网页后尝试检测某些页面元素时,它会抛出异常:

"org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM".

As the page is getting refreshed periodically,the DOM is getting changed. 由于页面会定期刷新,因此DOM也正在更改。 I can parse only few elements which is located at the upper portion of the DOM structure, because as the page is getting refreshed the internal DOM parser may not able to go inside after certain depth. 我只能解析位于DOM结构上部的少量元素,因为随着页面的刷新,内部DOM解析器可能无法在一定深度后进入内部。 So in this situation I am not able to traverse the whole DOM,won't able to fetch the lower portion of the DOM . 因此,在这种情况下, 我将无法遍历整个DOM,也无法获取DOM的下部

So please guys kindly,give me a solution so that I can parse the whole page,can traverse the entire DOM tree. 因此,请大家给我一个解决方案,以便我可以解析整个页面,可以遍历整个DOM树。

Thanks in advance, 提前致谢,

I dont understand why you need to identify the elements in webpage if the page is getting refreshed continuously as you wont be able to perform any operation on it. 我不明白,如果页面不断刷新,为什么您需要标识网页中的元素,因为您将无法对其执行任何操作。 Nevertheless, try the following code to get the body tag to a WebElement object:- 尽管如此,请尝试以下代码将body标签获取到WebElement对象:

WebElement body = driver.getElement(By.tagname("body"))

Use this body object to find the rest of the elements. 使用此主体对象查找其余元素。

body.findElements(By.tagname("input"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Selenium WebDriver选择网页上的两个元素之一? - How to chose either of 2 elements on a Webpage using Selenium WebDriver? 如何在网页上使用带有 Java 的 Selenium WebDriver 验证工具提示文本 - How to verify tooltip text using Selenium WebDriver with java on a webpage 使用Selenium WebDriver / Javascript / Java从网页及其属性中扫描HTML DOM元素 - Scan HTML DOM elements from the webpage and their properties using Selenium WebDriver/Javascript/Java 如何检查 <ul> 列表使用Selenium WebDriver? - How to check all elements in a <ul> list using Selenium WebDriver? 如何使用Selenium WebDriver配置网页语言 - How to configure webpage language using selenium webdriver 如何使用Xpath Selenium WebDriver JAVA获取多个元素(div)? - How to get multiple elements (div) using Xpath Selenium WebDriver JAVA? 如何使用JAVA在Selenium WebDriver中通过XPath定位Web元素? - How to locate web elements by XPath in Selenium WebDriver using JAVA? 在中定位元素 <li> 在Java中使用Selenium Webdriver - Locating elements in <li> using selenium webdriver with java 使用Java检查元素在Selenium WebDriver中的位置 - Checking position of elements in Selenium WebDriver using Java 如何使用Selenium Webdriver正确查找网页的元素? - How does correctly find elements of a webpage with Selenium Webdriver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM