【问题标题】:@FindBy Selenium how to find ::before@FindBy Selenium 如何找到 ::before
【发布时间】:2021-09-09 09:57:58
【问题描述】:

::before 我在现场有以下结构,::before 是我应该点击的复选框,找到了一些主题,但没有@FindBy 注释。是否可以在代码中找到这个 ::before?

<span class="jJ">
<label class="kJ" data-test-id="checkbox_bonus_card">
<input class="mJ" type="checkbox" name="hasBonusCard" value="">
<span data-test-id="checkbox_bonus_card_text" class="lJ">
::before
</span>
</label>
</span>

我试过@FindBy(xpath = "//label[@data-test-id='checkbox_bonus_card'//span['::before']"),但没用。

如果我使用这样的东西:

@FindBy(xpath = "//input[@name='hasBonusCard']")
WebElement checkboxBonusCard;

出现错误:

Caused by: ElementClickInterceptedException: element click intercepted: Element <input class="mJ" type="checkbox" name="hasBonusCard" value=""> is not clickable at point (568, 78). Other element would receive the click: <span class="jJ">...</span>

【问题讨论】:

    标签: java css selenium xpath findby


    【解决方案1】:

    我认为它在您想与之交互的输入字段中:

    @FindBy(name = "hasBonusCard")
    WebElement bonusCard;
    

    :: 基本上就是这个意思:

    在 CSS 中,::before 创建一个伪元素,它是 选定的元素。它通常用于将装饰内容添加到 具有 content 属性的元素。

    更多:

    因为 ::after 和 ::before 是一个伪元素,它允许你 从 CSS 将内容插入页面(无需在 HTML)。虽然最终结果实际上不在 DOM 中,但它出现在 页面就像它一样 - 你看到它但无法真正找到它 以 xpath 为例

    阅读更多here

    【讨论】:

    • 不,不幸的是不是输入,我正在尝试定位输入,但出现点击拦截错误。
    • 你能分享完整的错误堆栈跟踪吗?以及您是如何使用@findBy 的?
    • 在主题中添加信息
    • 好的,这意味着元素不在 Selenium 视口中。您是否以全屏模式启动浏览器?如果否,则将其全屏启动。如果是,那么这个元素在 UI 中的什么位置?你必须滚动(鼠标)才能看到这个元素吗?
    • 实际上这个元素在 Selenium 视口中,浏览器以全屏模式启动。在主题中添加了屏幕截图 [::before]。此复选框在没有悬停的情况下可见。
    猜你喜欢
    • 1970-01-01
    • 2013-08-28
    • 2017-12-19
    • 1970-01-01
    • 2013-05-06
    • 2014-08-08
    • 2023-03-28
    • 1970-01-01
    • 2021-07-27
    相关资源
    最近更新 更多