Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.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 消息:没有这样的元素:无法定位元素:{quot;method";:“xpath";,“selector";:“html/body/div[2]/div[2]/div[3]/div[2]/div/div/div/div[2]/a[1]}_Python_Selenium_Xpath_Selenium Chromedriver_Findelement - Fatal编程技术网

Python 消息:没有这样的元素:无法定位元素:{quot;method";:“xpath";,“selector";:“html/body/div[2]/div[2]/div[3]/div[2]/div/div/div/div[2]/a[1]}

Python 消息:没有这样的元素:无法定位元素:{quot;method";:“xpath";,“selector";:“html/body/div[2]/div[2]/div[3]/div[2]/div/div/div/div[2]/a[1]},python,selenium,xpath,selenium-chromedriver,findelement,Python,Selenium,Xpath,Selenium Chromedriver,Findelement,我已经被这个错误困扰了很长时间,由于某种原因,即使我指定了xpath,它也找不到元素。似乎没有任何iframe,隐式或显式等待也不起作用。请提供帮助。因此问题是等待元素出现,然后单击它 from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select import time print('\n') prin

我已经被这个错误困扰了很长时间,由于某种原因,即使我指定了xpath,它也找不到元素。似乎没有任何iframe,隐式或显式等待也不起作用。请提供帮助。

因此问题是等待元素出现,然后单击它

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
import time

print('\n')
print("PROGRAM STARTING")
print('~~~~~~')
print('\n')
# initiate driver
driver = webdriver.Chrome()
driver.get('http://arcselfservice.sbcounty.gov/web/user/disclaimer')

#begin
driver.find_element_by_xpath('//*[@id="submitDisclaimerAccept"]').click()
driver.find_element_by_xpath('/html/body/div[2]/div[2]/div/div[3]/div[2]/div/div/div[2]/a[1]').click()
如果以后要更改为其他标记,请使用另一种方法

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[2]/div[2]/div/div[3]/div[2]/div/div/div[2]/a[1]"))).click()
进口

path = "//a/div/h1[text()='{}']/../..".format("Fictitious Business Names Application")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH ,path))).click()

错误即将出现,因为元素需要时间才能使用。请使用显式等待元素提取

一个小片段可以是:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
只是别忘了进口

WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH ,'/html/body/div[2]/div[2]/div/div[3]/div[2]/div/div/div[2]/a[1]'))).click()

看起来不像正确的xpath。您希望单击哪个元素。@arundeepchohan虚拟的企业名称应用程序,我诱导了一些等待来单击它,然后它就工作了。@Anthony Victor Motai投了赞成票,但由于我没有15个代表,所以它不会公开显示。
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By