使用selenium和AppiumForMac自动化mac桌面应用程序

时间:2017-12-08 12:50:55

标签: python macos selenium xpath

我使用语言Python使用selenium和AppiumForMac自动化mac桌面应用程序。我想找到一组具有相同xpath的元素。为此,我使用了“find_elements_by_xpath()”。但是在运行脚本时,我收到以下错误:

File "xxxxx_automation.py", line 740, in <module>
    createNewTemplate()
  File "xxxxx_automation.py", line 102, in createNewTemplate
    roles_supported = driver.find_elements_by_xpath("/AXApplication[@AXTitle='XXXXX']/AXWindow[@AXIdentifier='_NS:10' and @AXSubrole='AXStandardWindow']/AXSheet[0]/AXScrollArea[@AXIdentifier='_NS:220']/AXTable[@AXIdentifier='_NS:224']/AXRow[@AXSubrole='AXTableRow']/AXCell[0]/AXButton[@AXIdentifier='RoleCheckBoxButton']")
  File "/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 366, in find_elements_by_xpath
    return self.find_elements(by=By.XPATH, value=xpath)
  File "/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 858, in find_elements
    'value': value})['value']
  File "/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 297, in execute
    self.error_handler.check_response(response)
  File "/Library/Python/2.7/site-packages/selenium-3.5.0-py2.7.egg/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.

导致错误的代码段:

roles_supported = driver.find_elements_by_xpath("/AXApplication[@AXTitle='XXXXX']/AXWindow[@AXIdentifier='_NS:10' and @AXSubrole='AXStandardWindow']/AXSheet[0]/AXScrollArea[@AXIdentifier='_NS:220']/AXTable[@AXIdentifier='_NS:224']/AXRow[@AXSubrole='AXTableRow']/AXCell[0]/AXButton[@AXIdentifier='RoleCheckBoxButton']")
    for roleSupported in roles_supported:
        print "TEST"
        role_name=roleSupported.text
        print role_name
        if role_name == "RtpToMp4-QS":
            clickElement(roleSupported)
            break
            time.sleep(2)

有人可以帮忙吗?

0 个答案:

没有答案