Selenium 无法按名称找到表单元素
Selenium can't find a form element by name
我在这里做错了什么?浏览器打开并转到该页面,但我收到以下错误消息。我试过 xpath;我试过id...
回溯(最近调用最后):
File "", line 1, in ms()
File "C:/Users/mohsen/Google Drive/scraper/Code/ICRC.py", line 47, in ms ICRC_GetLinks()
File "C:/Users/mohsen/Google Drive/scraper/Code/ICRC.py", line 72, in ICRC_GetLinks EC.presence_of_element_located((By.NAME, "search_last_name")))
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace)
TimeoutException
密码是:
link = "https://iccrc-crcic.ca/find-a-professional/"
# this will open up new window with the url provided above
driver = webdriver.Chrome()
driver.get(link)
sleep(1)
WebDriverWait(driver,30).until(
EC.presence_of_element_located((By.NAME, "search_last_name")))
driver.find_element_by_name("search_last_name").send_keys("Smith")
该元素位于您需要切换的 iframe
内。诱导 WebDriverWait()
并等待 frame_to_be_available_and_switch_to_it
() 和后续 css selector
.
driver.get("https://iccrc-crcic.ca/find-a-professional/")
wait=WebDriverWait(driver,20)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src='https://secure.iccrc-crcic.ca/search-new/EN']")))
wait.until(EC.element_to_be_clickable((By.XPATH,"//input[@name='search_last_name']"))).send_keys("user1")
跳出iframe需要使用
driver.switch_to.default_content()
浏览器快照:
我在这里做错了什么?浏览器打开并转到该页面,但我收到以下错误消息。我试过 xpath;我试过id...
回溯(最近调用最后):
File "", line 1, in ms()
File "C:/Users/mohsen/Google Drive/scraper/Code/ICRC.py", line 47, in ms ICRC_GetLinks()
File "C:/Users/mohsen/Google Drive/scraper/Code/ICRC.py", line 72, in ICRC_GetLinks EC.presence_of_element_located((By.NAME, "search_last_name")))
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace)
TimeoutException
密码是:
link = "https://iccrc-crcic.ca/find-a-professional/"
# this will open up new window with the url provided above
driver = webdriver.Chrome()
driver.get(link)
sleep(1)
WebDriverWait(driver,30).until(
EC.presence_of_element_located((By.NAME, "search_last_name")))
driver.find_element_by_name("search_last_name").send_keys("Smith")
该元素位于您需要切换的 iframe
内。诱导 WebDriverWait()
并等待 frame_to_be_available_and_switch_to_it
() 和后续 css selector
.
driver.get("https://iccrc-crcic.ca/find-a-professional/")
wait=WebDriverWait(driver,20)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src='https://secure.iccrc-crcic.ca/search-new/EN']")))
wait.until(EC.element_to_be_clickable((By.XPATH,"//input[@name='search_last_name']"))).send_keys("user1")
跳出iframe需要使用
driver.switch_to.default_content()
浏览器快照: