【问题标题】:stale element reference: element is not attached to the page, while clicking a hidden button using xpath过时的元素引用:元素未附加到页面,同时使用 xpath 单击隐藏按钮
【发布时间】:2020-05-15 15:09:29
【问题描述】:

我正在尝试使用 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 attach to the page document

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

【问题讨论】:

    标签: java selenium selenium-webdriver xpath


    【解决方案1】:

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

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

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

    【讨论】:

    • 它是一个可点击的隐藏按钮,当光标悬停在它上面时可见。当鼠标悬停在它上面时,它的类更改为“bg-iconButton-button bg-common-nodrag bg-tool-maximize bg-tool -maximizeOver”
    猜你喜欢
    • 1970-01-01
    • 2021-12-15
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-23
    • 1970-01-01
    相关资源
    最近更新 更多