【发布时间】:2021-05-09 09:00:03
【问题描述】:
我正在使用 Appium 进行测试自动化。这将在 Windows 机器上运行,我们使用 python 来驱动 Appium。 我能够找到我正在使用的自动化应用程序的主窗口:
ApplicationWindow = self.driver.find_element_by_xpath("//Pane[@ClassName='wcl_manager1']")
然后我需要在 ApplicationWindow 中搜索我需要按下的按钮。我只知道按钮将包含某些文本,但也会有其他文本。如果我确定文本会是什么,那么我可以这样做:
MenuButton = ApplicationWindow.find_elements_by_xpath("//Button[@Name='Hub window']")
但我当然不能。
我查看了 xpath 文档,并认为“包含”部分是我所需要的,但对于我的生活,我无法正确地获取语法。
我尝试了多种语法选项:
find_elements_by_xpath("//Button[contains(name(), 'Hub']")
find_elements_by_xpath("//Button[contains(@Name='Hub']")
find_elements_by_xpath("//Button[contains(@Name, 'Hub']")
但似乎没有一个是灵丹妙药。
谁能指出 Python 和 Appium 的“包含”功能的正确语法?
谢谢!
【问题讨论】:
标签: python windows automated-tests appium