我想用
填写表格driver.find_element_by_id("name").send_keys("Test")
但每次运行脚本时都会出现此错误:
Traceback (most recent call last):
File "fill.py", line 22, in <module>
driver.find_element_by_id("name").send_keys("Test")
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 351, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 955, in find_element
'value': value})['value']
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to execute 'contains' on 'Node': parameter 1 is not of type 'Node'.
(Session info: chrome=66.0.3359.117)
(Driver info: chromedriver=2.38.552518 (183d19265345f54ce39cbb94cf81ba5f15905011),platform=Mac OS X 10.13.4 x86_64)
<input first_and_last="true" placeholder="name" class="string required" type="text" name="flname" id="name">
&#13;
注意:我在搜索名称时也会收到错误消息。如果我搜索Xpath,它会非常慢地填写表单,我需要它更快。
我该如何解决这个问题?
答案 0 :(得分:0)
使用定位器策略中的任何一个:
css_selector :
driver.find_element_by_css_selector("input.string.required#name").send_keys("Test")
xpath :
driver.find_element_by_xpath("//input[@class='string required' and @id='name']").send_keys("Test")
我试图寻找您遇到的两个错误消息的解决方案,以下是相关详细信息:
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to execute 'contains' on 'Node': parameter 1 is not of type 'Node'.
:根据讨论typeError: Failed to execute 'contains' on 'Node': parameter 1 is not of type 'Node Polymer,您的应用程序可能基于 Polymer ,并且在 Page之后不久开始寻找任何元素之前加载作为预防措施会导致服务员通过WebDriverWait以及正确的expected_conditions
Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'."
:根据讨论JS: Failed to execute 'getComputedStyle' on 'Window': parameter is not of type 'Element'和Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element' error指向类似的行为,即当 JavaScript <时,所需元素实际上不存在于DOM中/ em>或 Ajax Call 正致力于添加/删除元素。