admin管理员组文章数量:1313292
I'm trying to upload a png via selenium. My Problem is, that the Input I need to use, is invisible to selenium, but not to the user. In the FAQ of Selenium they told me to use the JavascriptExcecutor like:
((JavascriptExecutor)driver).executeScript("arguments[0].style.visibility = 'visible'; arguments[0].style.height = '1px'; arguments[0].style.width = '1px'; arguments[0].style.opacity = 1", fileUploadElement);
I used this with C# in the past, and it worked, but now im struggeling to convert that usage to python. I would use the document.getElementByName()
function, but the input doesn't have a Name and there are more than one on the page. What is the best way to solve that Problem. I already tried
icon = element.find_element_by_css_selector("input")
script_befehl = icon+".style.visibility = 'visible'; "+icon+".style.height = '1px'; "+icon+".style.width = '1px'; "+icon+".style.opacity = 1
but that also didn't work, i'm getting a Syntax error
I'm trying to upload a png via selenium. My Problem is, that the Input I need to use, is invisible to selenium, but not to the user. In the FAQ of Selenium they told me to use the JavascriptExcecutor like:
((JavascriptExecutor)driver).executeScript("arguments[0].style.visibility = 'visible'; arguments[0].style.height = '1px'; arguments[0].style.width = '1px'; arguments[0].style.opacity = 1", fileUploadElement);
I used this with C# in the past, and it worked, but now im struggeling to convert that usage to python. I would use the document.getElementByName()
function, but the input doesn't have a Name and there are more than one on the page. What is the best way to solve that Problem. I already tried
icon = element.find_element_by_css_selector("input")
script_befehl = icon+".style.visibility = 'visible'; "+icon+".style.height = '1px'; "+icon+".style.width = '1px'; "+icon+".style.opacity = 1
but that also didn't work, i'm getting a Syntax error
Share Improve this question edited Sep 8, 2014 at 13:46 alecxe 474k127 gold badges1.1k silver badges1.2k bronze badges asked Sep 8, 2014 at 13:38 ChorgoChorgo 611 silver badge6 bronze badges 1- Invisible to Selenium but not to the user? How does that work? Sounds like there is an extra step to "make it visible" that you aren't doing. Are you sure it's invisible? If you interact with it, what does Selenium do? – Arran Commented Sep 8, 2014 at 14:39
2 Answers
Reset to default 5There is an execute_script()
method on the driver instance, arguments are passed to it in a similar to C#'s JavascriptExecutor
:
icon = element.find_element_by_css_selector("input")
driver.execute_script("arguments[0].style.visibility = 'visible'; arguments[0].style.height = '1px'; arguments[0].style.width = '1px'; arguments[0].style.opacity = 1", icon)
In my case, the invisibility of the element was due to having display:none;
in the style.
So the solution was:
driver.execute_script("arguments[0].style.display = 'block';", element)
本文标签: Make WebElement visible via Selenium with Python with JavaScriptStack Overflow
版权声明:本文标题:Make WebElement visible via Selenium with Python with JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741924428a2405198.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论