javascript错误的execute_script问题

时间:2019-01-30 05:46:03

标签: javascript internet-explorer selenium-webdriver

此代码可在chrome上完美运行,但不能在IE上运行:

from selenium import webdriver
my_driver = webdriver.Ie()
#go to the page
my_driver.execute_script("window.location.href = 'https://url.com';")
#input login                         
my_driver.execute_script("document.getElementById('user').value='name';")
#input pwd
my_driver.execute_script("document.getElementById('pwd').value='1234';")
#submit
my_driver.execute_script('$(":button").click()')

print('Done!')

我收到此错误,并且输入未填写:

Traceback (most recent call last):
File "D:/Projects/Project-3/solution1.py", line 6, in <module>
my_driver.execute_script("document.getElementById('user').value='name';")
File "C:\Users\corentin.fleurance\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 636, in 
execute_script
'args': converted_args})['value']
File "C:\Users\corentin.fleurance\AppData\Local\Programs\Python\Python37- 
32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in 
execute
self.error_handler.check_response(response)
File "C:\Users\corentin.fleurance\AppData\Local\Programs\Python\Python37- 
32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, 
in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.JavascriptException: Message: Error executing 
JavaScript

.value()似乎不是由IE处理的,但是我不知道该用什么来替代它。我正在使用js,因为sendKeys太慢,因此我必须使用IE。 有人有主意吗?

0 个答案:

没有答案