【问题标题】:unknown error: Unsupported locator strategy: By未知错误:不支持的定位器策略:通过
【发布时间】:2018-06-14 19:22:58
【问题描述】:

我正在尝试将 selenium 与 python 一起使用,但在尝试使用 webdriver.expectedConditions 类时遇到了问题。

以下代码摘自几个类,但包含了所有必要的代码:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

def isVisible(self, driver, HOW, WHAT, timeout=2):
    locator=(HOW,WHAT)
    try:
        WebDriverWait(driver, timeout).until(EC.visibility_of_element_located(locator))
        return True
    except TimeoutException:
        return False

newApplicationXpath = "//input[@value='New']"
self.assertTrue(self.isVisible(self.driver, "By.XPATH",     newApplicationXpath, 120))

追溯:

WebDriverException:消息:未知错误:不支持的定位器策略:通过 (会话信息:chrome=66.0.3359.139) (驱动信息:chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 4.1.12-112.14.10.el7uek.bug27766149.x86_64 x86_64)

【问题讨论】:

    标签: python selenium


    【解决方案1】:

    如果没有更多代码可以关闭(您提供的示例非常不完整),我将假设您的错误是因为您将“By.XPATH”作为字符串传递,而不是作为By.XPATH .将代码的最后一行更改为:

    self.assertTrue(self.isVisible(self.driver, By.XPATH, newApplicationXpath, 120))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-29
      • 2022-11-03
      • 2019-07-18
      • 2012-08-16
      • 2019-10-22
      • 1970-01-01
      • 2016-07-28
      • 2022-01-10
      相关资源
      最近更新 更多