Java和Selenium:Extreme StaleelementReferenceException
我正在遇到一种staleelementReference侵害,在应用程序中似乎超出了所有原因。它绝对不涉及页面的刷新或重新加载,而只需连续两个访问该元素的操作 - 一键单击和一个断言未选择该元素。
Java/Selenium Code:
this.element.findElement(By.cssSelector("input[type='checkbox']")).sendKeys(Keys.SPACE);
(SPACE is used because when usng click, Selenium claims "ElementClickInterceptedExcpetion - other element would receive the click")
assertThat(this.element.findElement(By.cssSelector("input[type='checkbox']")).isSelected()).isFalse();
这将导致:
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
即使我使用制动点在int code上,并缓慢跳过每个步骤。
标记:
<div class="hb-cell hb-cell--autoWidth">
<input tusenskilletegn="" id="utgift-2-belop">
<input type="checkbox" id="utgift-2-inkludert">
<div class="hb-label>
<label class="hb-label-tekst" for="utgift-2-inkludert"></label>
</div>
</div>
尝试访问“标签中的for
this.element.findElement(By.cssSelector("label[for$=-inkludert]")).click();
还
org.openqa.selenium.ElementNotInteractableException: element not interactable
” “在这个地方”。
I'm experiencing a StaleElementReferenceExpection that seems beyond all reason in an application. It involves absolutely no refreshing or reloading of the page, but just two consecutive actions of accessing the element - one click and one assertion that the element is not selected.
Java/Selenium code:
this.element.findElement(By.cssSelector("input[type='checkbox']")).sendKeys(Keys.SPACE);
(SPACE is used because when usng click, Selenium claims "ElementClickInterceptedExcpetion - other element would receive the click")
assertThat(this.element.findElement(By.cssSelector("input[type='checkbox']")).isSelected()).isFalse();
This results in:
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
even when I use brake points int the code, and skip slowly through each step.
Markup:
<div class="hb-cell hb-cell--autoWidth">
<input tusenskilletegn="" id="utgift-2-belop">
<input type="checkbox" id="utgift-2-inkludert">
<div class="hb-label>
<label class="hb-label-tekst" for="utgift-2-inkludert"></label>
</div>
</div>
Also tried accessing the for" in the label, with no luck: (using partial match, in this example)
this.element.findElement(By.cssSelector("label[for$=-inkludert]")).click();
It results in
org.openqa.selenium.ElementNotInteractableException: element not interactable
Any ideas? Selenium seems to have become impossible for me to use lately, with this type of error occuring all "over the place".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在click()函数中遇到问题,则可以随时使用js单击它,
而不是添加任意线程。陈旧,然后再次找到元素。
If you have issues with the click() function you could always just click it using JS
As for the StaleElementReferenceExpection instead of adding an arbitrary Thread.sleep you could just write a little helper method using ExpectedConditions to click it and wait for the element to go stale, then just find the element again.