过时的元素引用:使用 XPath 单击隐藏按钮时,元素未附加到页面



我正在尝试使用硒中的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: 过时的元素引用: 元素未附加到页面文档

我想我正面临这个问题,因为它被封装为div而不是按钮。

首先,你可以通过它的ID而不是它的Xpath来选择你的元素。

WebElement fullscreenbutton = UtilityFunc.driver.findElement(By.id("bg-po-full-screen-1"));

其次,您尝试单击的元素没有与之关联的 onClick 事件,也不是按钮。您确定您的实际按钮没有嵌套在其中或位于其下方吗?

最新更新