How to change the visibility of the button got by Xpath in Selenium

孤街浪徒 提交于 2019-12-11 07:12:58

问题


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

The Xpath of button is

"//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();

Can anyone help me out ?


回答1:


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();



回答2:


I think the following procedure will help

  1. using Actions, hover over the element step
  2. insert an implicit wait till the element is visible
  3. click the button


来源:https://stackoverflow.com/questions/16954144/how-to-change-the-visibility-of-the-button-got-by-xpath-in-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!