如何更改Xelete在Selenium中获得的按钮的可见性 [英] How to change the visibility of the button got by Xpath in Selenium

查看:68
本文介绍了如何更改Xelete在Selenium中获得的按钮的可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用Nunit进行Selenium Automation测试.我有一个拥有大量用户的网格,并且网格的每一行上都有一个删除按钮.但是该删除"按钮仅在鼠标悬停时可见.因此,当我运行脚本时,它给了我错误-

Hello I am working in Selenium Automation testing with Nunit. I have one grid which have bulk of users and there is one remove button on each row of the grid. But that Remove button is visible only on mouse hover. So when I run the script, It gives me the error -

Element is not currently visible and so may not be interacted with

按钮的Xpath是

"//div [1]/div [2]/div/section/div [2]/div [包含(.,'IE8 john smith')]/div/div [2]/button [1]"

"//div[1]/div[2]/div/section/div[2]/div[contains(.,'IE8 john smith')]/div/div[2]/button[1]"

我尝试使用硒中的作用,但仍然给我同样的错误.

I tried working with the actions in selenium but still it gives me the same error.

Actions actions = new Actions(Driver);
            var element = Driver.FindElement(By.XPath("//div[1]/div[2]/div/section/div[2]/div[contains(.,'" + fullName + "')]/div/div[2]/button[1]"));
            actions.MoveToElement(element);
            actions.Click();
            actions.Perform();

有人可以帮我吗?

推荐答案

尝试使用JS强制元素可见:

Try to force element to be visible using JS:

 IWebElement element = driver.FindElement();
  js.ExecuteScript("arguments[0].style.visibility = 'visible', arguments[0].style.height = '1px'; arguments[0].style.width = '1px'; arguments[0].style.opacity = 1", element);
  element.Click();

这篇关于如何更改Xelete在Selenium中获得的按钮的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆