Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.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 2.7 Selenium Python,Web驱动程序等待查找元素,查找元素不_Python 2.7_Google Chrome_Selenium - Fatal编程技术网

Python 2.7 Selenium Python,Web驱动程序等待查找元素,查找元素不

Python 2.7 Selenium Python,Web驱动程序等待查找元素,查找元素不,python-2.7,google-chrome,selenium,Python 2.7,Google Chrome,Selenium,以下代码在firefox中运行良好,无需睡眠(1)。 但是在chrome中,driver.find\u element\u by\u xpath失败。 如果中间有sleep(1),则它可以工作 //the wait below passes fine for both Chrome and Firefox. WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="taketour"]/

以下代码在firefox中运行良好,无需
睡眠(1)
。 但是在chrome中,
driver.find\u element\u by\u xpath
失败。 如果中间有
sleep(1)
,则它可以工作

//the wait below passes fine for both Chrome and Firefox.

WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="taketour"]/div/div[1]/a/span')))

//In chrome this does not find the element.Works in firefox.

driver.find_element_by_xpath('//*[@id="taketour"]/div/div[1]/a/span').click()
在chrome中显示一个

ElementNotVisibleException: Message: Message: element not visible
下面的代码适用于Chrome和Firefox

WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="taketour"]/div/div[1]/a/span')))

sleep (1)

driver.find_element_by_xpath('//*[@id="taketour"]/div/div[1]/a/span').click()

您不能单击尚未可见的元素,请改用所定位元素的预期条件可见性。\u:

// Wait until element is visible    
WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="taketour"]/div/div[1]/a/span')))

driver.find_element_by_xpath('//*[@id="taketour"]/div/div[1]/a/span').click()
或者更好的是,由于您正试图单击该元素,您还可以等待该元素可单击:

// Wait until element is clickable
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="taketour"]/div/div[1]/a/span')))

driver.find_element_by_xpath('//*[@id="taketour"]/div/div[1]/a/span').click()

有关可用于检查元素状态的更为方便的方法,请参阅。

如果无法单击尚未可见的元素,请改用位于的元素的预期条件可见性:

// Wait until element is visible    
WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="taketour"]/div/div[1]/a/span')))

driver.find_element_by_xpath('//*[@id="taketour"]/div/div[1]/a/span').click()
或者更好的是,由于您正试图单击该元素,您还可以等待该元素可单击:

// Wait until element is clickable
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="taketour"]/div/div[1]/a/span')))

driver.find_element_by_xpath('//*[@id="taketour"]/div/div[1]/a/span').click()

有关可用于检查元素状态的更方便的方法,请参阅。

与firefox相比,chrome似乎需要花费时间来显示元素。chrome确实找到了元素,只是还不可见。不要等到找到的元素出现,而是尝试使用“等到找到的元素的可见性”。与firefox相比,chrome似乎需要花费时间来显示该元素。chrome确实找到了该元素,只是它还不可见。不要等到找到的元素出现,而是尝试使用“等到找到的元素的可见性”。看见