简体   繁体   English

javascriptexecutor-无法单击带有身体样式标签为“ overflow:hidden”的元素

[英]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,我在这里给出答案,我将您的弹出窗口关闭,如下所示:

Element Not visible error 元素不可见错误

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.

相关问题 通过单击菜单将溢出设置为隐藏在身体上 - Set overflow to hidden on body by click on menu Skrollr导致干预错误并更改body和html的element.style使其溢出:隐藏 - Skrollr causing intervention error and changing element.style of body and html to overflow: hidden 当使用data-container =“ body”属性来解决溢出问题时,我的自定义引导工具提示样式将被覆盖:hidden div元素 - My custom bootstrap tooltip style gets overriden when using data-container=“body” attribute to work around overflow:hidden div element 溢出隐藏添加在body标签中,从而删除了滚动条 - overflow hidden adding in body tag which remove the scrollbar 我需要溢出:隐藏; 在 body 标签中,但需要滚动不会消失 - I need overflow: hidden; in body tag but need that the scroll does not disappear 添加隐藏到身体的溢出 - Adding overflow hidden to body JavaScript主体溢出:隐藏 - Javascript body overflow: hidden 使用JavascriptExecutor发送Keys并单击web元素 - Using JavascriptExecutor to sendKeys plus click on web element JavaScript:在溢出自动中单击时显示隐藏元素 - JavaScript: show hidden element on click in overflow-auto 单击并拖动带有溢出的元素:隐藏不会在firefox中触发onmouseout - Click and drag element with overflow: hidden doesn't trigger onmouseout in firefox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM