Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 未知错误:不支持的定位器策略:由_Python_Selenium - Fatal编程技术网

Python 未知错误:不支持的定位器策略:由

Python 未知错误:不支持的定位器策略:由,python,selenium,Python,Selenium,我试图将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 a

我试图将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),平台=Linux 4.1.12-112.14.10.el7uek.bug27766149.x86_64 x86_64)


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


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

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