[英]javascriptexecutor -Not able to click element with body style tag as “overflow:hidden”
hi when we have to change tags attribute value with the help of javascriptexecutor in selenium webdriver (java) we use like belwo : 嗨,当我们不得不借助selenium webdriver(java)中的javascriptexecutor更改标签属性值时,我们像belwo一样使用:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('//id of element').setAttribute('attr', '10')");
and elements attribute is changed. 和elements属性已更改。
Also while automating a website i have to click a button i have used normal webdriver 另外,在自动化网站时,我必须单击一个按钮,我已经使用了普通的webdriver
driver.findElement(By.xpath("//*[data-dismiss='modal']").click();
to click it but always i got Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: element not visible . 单击它,但总是在线程“ main” org.openqa.selenium.ElementNotVisibleException中得到异常:元素不可见 。 the html source for that button is 该按钮的html源是
<button class="indigo-submit btnStyle clsmdl" data-dismiss="modal" aria-hidden="true">Close</button>
also i have noticed that if i use Actions of selenium over the button i get no exception but even no click at the button ie my script pass with no exception but also it does not click. 我也注意到, 如果我在按钮上使用硒的作用,我不会例外,甚至在按钮上也不会单击,即我的脚本无一例外都通过了,但它也不会单击。 after doing a lot search what i found that 经过大量搜索之后,我发现了
<body style="overflow: hidden;">
...
...
< <button class="indigo-submit btnStyle clsmdl" data-dismiss="modal" aria-hidden="true">Close</button>
...
...
</body>
Style attribute of body tag is "overflow:hidden" which as per How to check what is causing a web element to be invisible to Python Selenium? 根据如何检查导致Web元素对Python Selenium不可见的内容 ,body标签的样式属性为“ overflow:hidden” 。 link Some users say Selenium cannot click a web element which is under a parent node with overflow: hidden.Also i have tried the suggestion provided in the link but no luck ,may be i am not able to convert python code into java correctly. 链接一些用户说Selenium无法单击父节点下带有溢出的Web元素:hidden.Also我也尝试了链接中提供的建议,但没有运气,可能是我无法正确将python代码转换为java。
1.Now Please help me how can i use javascriptexceutor to change the body style tag to
visible.
2.Please help me how can i use javascriptexceutor to change the button aria-hidden tag to
false. Also i want a way to verify the same.
@raj N ish Ku M ar, i give the answer here, i close ur pop up in my machine like below: @raj Nish Ku M ar,我在这里给出答案,我将您的弹出窗口关闭,如下所示:
I'm also not sure that I can convert Python
to Java
correctly :) Try following: 我也不确定是否可以正确将Python
转换为Java
:)尝试以下操作:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementsByClassName('indigo-submit btnStyle clsmdl')[0].aria-hidden='false'");
If you want to change element style use JavaScript
like this: 如果要更改元素样式,请使用JavaScript
如下所示:
document.getElementsByClassName('indigo-submit btnStyle clsmdl')[0].style.visibility="visible";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.