使用Selenium、Python填充web表单

2024-09-30 12:31:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图填补this form以改善我的工作,我尝试了硒,但出现了一些问题:

driver= webdriver.Chrome('/Users/48604/Desktop/kyk/chromedriver')
driver.get('https://quintadb.com/widgets/cCsqTdWRnaWPBdGb4zgCkg/c_mw7dRmneW4mgWQzrFdOq')
fill = driver.find_element_by_xpath("//input[@name='dtype[cTqIlcPGbjsk_cIuZdPSoQ]' and @id='dtype_cTqIlcPGbjsk_cIuZdPSoQ']").click()
fill.send_keys('test')

但我得到了一个错误:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@name='dtype[cTqIlcPGbjsk_cIuZdPSoQ]' and @id='dtype_cTqIlcPGbjsk_cIuZdPSoQ']"}

我也试过:

 fill = driver.find_element_by_xpath("//input[@name='dtype[cTqIlcPGbjsk_cIuZdPSoQ]' and @id='dtype_cTqIlcPGbjsk_cIuZdPSoQ']").click()[0]

但还是不起作用,知道吗


Tags: andnameidinputbydriverelementfind
1条回答
网友
1楼 · 发布于 2024-09-30 12:31:13

.click()带到下一行:

fill = driver.find_element_by_xpath("//input[@name='dtype[cTqIlcPGbjsk_cIuZdPSoQ]' and @id='dtype_cTqIlcPGbjsk_cIuZdPSoQ']")
fill.click()
fill.send_keys('test')

输出:

enter image description here

您的代码无法工作,因为您已将.click()函数的输出分配给变量fill。当您打印出代码中的填充类型时,它将打印以下内容:

fill = driver.find_element_by_xpath("//input[@name='dtype[cTqIlcPGbjsk_cIuZdPSoQ]' and @id='dtype_cTqIlcPGbjsk_cIuZdPSoQ']").click()
print(type(fill))

输出:

<class 'NoneType'>

类型为NoneType的变量没有名为.send_keys()的函数。因此,您的代码不起作用

相关问题 更多 >

    热门问题