Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t使用Selenium+执行Js脚本;python_Python_Selenium_Automated Tests - Fatal编程技术网

Can';t使用Selenium+执行Js脚本;python

Can';t使用Selenium+执行Js脚本;python,python,selenium,automated-tests,Python,Selenium,Automated Tests,我在UI中有一些日期输入,当我尝试在其中填充日期时遇到了一个问题-在填充并切换到下一个输入后,日期会被删除。我决定执行Js脚本,它将更改输入值并设置正确的日期 因此,我这样做: wd.find_element_by_css_selector('input[value\\.bind="data.object[\'construction_date\']"]').execute_script("'$('input').val('01.01.1991')") 并在执行时获得AttributeEr

我在UI中有一些日期输入,当我尝试在其中填充日期时遇到了一个问题-在填充并切换到下一个输入后,日期会被删除。我决定执行Js脚本,它将更改输入值并设置正确的日期

因此,我这样做:

wd.find_element_by_css_selector('input[value\\.bind="data.object[\'construction_date\']"]').execute_script("'$('input').val('01.01.1991')")
并在执行时获得AttributeError:

 AttributeError: 'WebDriver' object has no attribute 'window'

如何解决此问题?

如果要使用
JavaScriptExecutor
更改元素的
,可以尝试:

element = wd.find_element_by_css_selector('input[value\\.bind="data.object[\'construction_date\']"]')
wd.execute_script('arguments[0].value="01.01.1991";', element)

它使用这种结构:
element=wd。通过css\u选择器查找元素(输入[value\\.bind=“data.object[\'construction\u date\']”)wd。执行脚本(参数[0]。value=“01.01.1991”;,element)wd。通过css\u选择器查找元素(输入[value\\.bind=“data.object[\'construction\u date\']”)。发送密钥(新房子。建筑日期)
如果在更改输入值后不执行send_keys()方法,则不会。我建议不要这样做,因为没有用户会使用JS填写日期。您所走的道路不是用户场景。你能分享这个页面的链接吗?