我正在尝试使用 selenium 中的 xpath 单击以下按钮,
<div class="bg-iconButton-button bg-common-nodrag bg-tool-maximize bg-common-hideDisplay" title="Display in full screen" id="bg-po-full-screen-1"></div>
我尝试了下面的代码,
fullscreenbutton=UtilityFunc.driver.findElement(By.xpath("//*[@id='bg-po-full-screen-1']"));
KeywordFunc.fnClick(fullscreenbutton);
我收到以下错误,
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
我认为我面临这个问题,因为它是作为 div 而不是按钮封闭的。
最佳答案
首先,您可以通过元素的 ID 而不是 Xpath 来选择元素。
WebElement fullscreenbutton = UtilityFunc.driver.findElement(By.id("bg-po-full-screen-1"));
其次,您尝试单击的元素没有与之关联的 onClick 事件,也不是按钮。您确定您的实际按钮没有嵌套在其中或位于其下方吗?
关于java - 使用 xpath 单击隐藏按钮时出现陈旧元素引用 : element is not attached to the page,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61822438/