首页 > 解决方案 > Firefox 和 geckodriver 更新后定位器出现问题

问题描述

我们有一个采用 Vaadin 技术的网站。

Test environment:
firefox-56.0.1 
geckodriver: 0.20.0 
Robotframework 4.1.1
selenium       3.141.0 
Python 3.7.3 

这个 Python 脚本正在运行,机器人可以点击这个定位器。

GetElement.py

    def Get_Element_hmenu():
        Lib = BuiltIn().get_library_instance('SeleniumLibrary')
        Driver = Lib.driver
        host1 = Driver.find_element_by_xpath("//vaadin-context-menu-item[@id='FILE_MENU']")
        return host1

test.robot<br>
<br>

       ${Element}=  Get_Element_hmenu
       Log  ${Element}
       Click Element   ${Element}

如果我更新这个组件

Firefox 92.0.1
Geckodriver  0.30.0

更新后此代码不起作用。

NoSuchElementException: Message: Unable to locate element: //vaadin-context-menu-item[@id='FILE_MENU']

你有什么想法,我该怎么办?非常感谢

HTML 代码 在此处输入图像描述

标签: pythonhtmlselenium-webdriverxpathvaadin

解决方案


在 Firefox 63 中添加了Shadow DOM支持。在您之前使用 Firefox 56 的设置中,使用了 shadydom polyfill,因为没有影子根封装,这使得 vaadin-context-menu-item 可以在元素查询中找到。

更新 Firefox 版本后有影子根,您需要在其中搜索。查看屏幕截图中的 dom 树,您需要选择 vaadin-menu-bar 内的影子根,并在该上下文中搜索 vaadin-context-menu-item。这个答案有一些如何做到这一点的例子。


推荐阅读