我正在尝试使用Python
在Firefox
中做我的第一个Web抓取项目。我正在使用Python version 3.7.4
和Firefox Developer 71
。两者都是64位,我正在使用Windows 10
。
问题正在尝试通过python
访问此表单控件。最终,我想将文本插入到表单控件中,然后通过Web抓取结果。但是,由于它很难获取,因此我现在只是尝试单击该对象。
这是我的代码:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
import time
driver = webdriver.Firefox()
driver.get("https://www.website.com/login/")
jcode_form = driver.find_element_by_id('ndcCode')
hov = ActionChains(driver).move_to_element(jcode_form)
time.sleep(6)
hov.click()
hov.perform()
我收到的错误说:
WebDriverException:消息:TypeError:矩形未定义
Here is what I'm seeing on my browser
我要使用的对象是顶部的表单控件。
我已经尝试使用动作链和睡眠功能以多种方式解决此问题,但是我一直收到错误消息。
任何帮助或建议,将不胜感激。谢谢。
以下内容可能会解决它:
jcode_form = driver.find_element_by_id('ndcCode')
jcode_form.click()
或在一行中:
driver.find_element_by_id('ndcCode').click()