![](/img/trans.png)
[英]Python selenium how to execute execute_script on a JavaScript element with arguments
[英]Selenium+firefox: empty execute_script arguments
我正在尝试使用javascript而不是send_keys()方法设置textarea
值。
正如文档所说,我应该能够将webelement传递给execute_script作为参数,并通过arguments
数组引用此参数。 但是,我已经在firefox js控制台中检查过, arguments
是Object,并且我将它作为execute_script参数放置并不重要 - arguments
始终是一个空对象。
>>>> web = webdriver.Firefox()
>>>> web.get("http://somepage.com")
>>>> element = web.find_element_by_tag_name("textarea")
>>>> web.execute_script("return typeof(arguments)", element)
u'object'
>>> web.execute_script("return arguments",element)
[]
任何人都有类似主题的经验吗? 如何将webElement作为javascript的参数?
使用Firefox 35.0,selenium 2.44.0。
以下是相关的错误: Firefox 35:将参数传递给executeScript不起作用 。
这是在今天发布的硒2.45中修复的, 升级硒包 :
pip install --upgrade selenium
老答案:
我能够使用selenium==2.44.0
和Firefox 35.0
重现问题:
>>> element = web.find_element_by_tag_name('textarea')
>>> web.execute_script("return arguments",element)
[]
降级到Firefox 34.0.5
解决了这个问题:
>>> element = web.find_element_by_tag_name('textarea')
[<selenium.webdriver.remote.webelement.WebElement object at 0x1022d1bd0>]
在版本35中,Selenium无法再使用Firefox中传递的参数执行javascript .Selenium已经能够通过一种称为__exposedProps__的后门传递参数。 作为整体收紧外部绑定界面的一部分(以及一些繁忙的工作,由他们从谷歌提供的所有资金资助),他们弃用,然后删除了这个界面。 他们的意图记录在2014年中期的弃用通知中 。 Selenium bug #8390涵盖了它,但我认为这让开发团队感到意外,我没有看到任何活动迁移到另一个界面,我认为这将是WebIDL 。
它不会影响其他浏览器,但Firefox是迄今为止使用Selenium进行测试的最快捷,最简单的方法。 目前,我们网络测试人员的最佳选择是降级到Firefox 34并关闭自动更新,直到有可用的分辨率。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.