最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Selenium+firefox: empty execute_script arguments - Stack Overflow

programmeradmin1浏览0评论

I'm trying to set textarea value using javascript instead send_keys() method.

As documentation says, I should be able to pass webelement to execute_script as parameter and refer to this parameter via arguments array. However, I've checked in firefox js console, that arguments is Object and it doesn't matter what i put as execute_script argument - arguments is always an empty object.

>>>> web = webdriver.Firefox()
>>>> web.get("")
>>>> element = web.find_element_by_tag_name("textarea")
>>>> web.execute_script("return typeof(arguments)", element)
u'object'
>>> web.execute_script("return arguments",element)
[]

Anyone has any experience with similarly subject? How can I put webElement as argument for javascript?

Using Firefox 35.0, selenium 2.44.0.

I'm trying to set textarea value using javascript instead send_keys() method.

As documentation says, I should be able to pass webelement to execute_script as parameter and refer to this parameter via arguments array. However, I've checked in firefox js console, that arguments is Object and it doesn't matter what i put as execute_script argument - arguments is always an empty object.

>>>> web = webdriver.Firefox()
>>>> web.get("http://somepage.")
>>>> element = web.find_element_by_tag_name("textarea")
>>>> web.execute_script("return typeof(arguments)", element)
u'object'
>>> web.execute_script("return arguments",element)
[]

Anyone has any experience with similarly subject? How can I put webElement as argument for javascript?

Using Firefox 35.0, selenium 2.44.0.

Share Improve this question edited Jan 19, 2015 at 19:56 alecxe 475k127 gold badges1.1k silver badges1.2k bronze badges asked Jan 19, 2015 at 18:37 ASmith78ASmith78 1538 bronze badges 2
  • Interesting, I cannot reproduce it, the latter statement prints: [<selenium.webdriver.remote.webelement.WebElement object at 0x1022d1bd0>]. Which selenium and firefox versions are you using? – alecxe Commented Jan 19, 2015 at 18:46
  • selenium.__version__ '2.44.0' Firefox - 35.0 – ASmith78 Commented Jan 19, 2015 at 18:53
Add a ment  | 

2 Answers 2

Reset to default 5

Here is the relevant bug: Firefox 35: Passing arguments to executeScript isn't working.

Which was fixed in selenium 2.45 which was released today, upgrade selenium package:

pip install --upgrade selenium

Old answer:

I was able to reproduce the problem using selenium==2.44.0 and Firefox 35.0:

>>> element = web.find_element_by_tag_name('textarea')
>>> web.execute_script("return arguments",element)
[]

Downgrading to Firefox 34.0.5 solved the issue:

>>> element = web.find_element_by_tag_name('textarea')
[<selenium.webdriver.remote.webelement.WebElement object at 0x1022d1bd0>]

Selenium can no longer execute javascript with passed parameters in Firefox, as of version 35. Selenium has been able to pass in arguments via a kind of backdoor known as __exposedProps__. As part of an overall tightening up of the external bindings interface (and some busywork, financed by all of that money they made from Google), they deprecated, and then removed, this interface. Their intention was documented in a deprecation notice in mid-2014. Selenium bug #8390 covers it, but I take it this caught the dev team by surprise and I don't see any activity to migrate to another interface yet, which I presume will be WebIDL.

It doesn't affect other browsers, but Firefox is by far the quickest and easiest method of testing with Selenium. Currently, the best option for us web testers is to just downgrade to Firefox 34 and turn off automatic updates until a resolution is available.

发布评论

评论列表(0)

  1. 暂无评论