1

I am using Selenium in C# to Enter data into textboxes on a webpage:

But i am getting this error:

OpenQA.Selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with

I'm using @name, but there are 2 controls on the page with name="MinPrice"

heres the HTML:

<div class="form-group for-sale">
    <label>Min Price</label>
    <input class="form-control" name="MinPrice" min="0" placeholder="Minimum Price" value="" type="number"></input>

and this is the xpath I'm using:

txtMinPrice = Driver.Instance.FindElement(By.Name("MinPrice"));

I also tried using XPath, but similar results:

txtMinPrice = Driver.Instance.FindElement(By.XPath("//input[contains(@name,'MinPrice') and type='number']"));

If anyone has any type of idea....this is driving me nuts.

  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – AntiTcb May 25 '16 at 17:53
  • @AlexGravely That has nothing to do with this question. – Rob May 26 '16 at 23:54

3 Answers3

1

ElementNotVisibleException exception occurs when selenium can find an element in the DOM but it is not rendered on the screen.

When I have encountered this error before it has been generally caused by one of three things:

  1. Selenium is trying to interact with an object that is present in the DOM but has not yet rendered on the screen, in which case you might consider adding some type of delay. (Avoid sleep if you can but it is useful for debugging)
  2. The element is below the visible screen, in which case you would need to scroll to interact with it.
  3. There is an overlapping element that is blocking the display of the element.
  • I tried adding an implictWait, and a Sleep but that didn't help. I have the page set to maximize upon load, so the element is in view. And doesnt seem that anything is overlapping the element, blocking it. I'm not sure what else to try – Angela Rauws May 26 '16 at 15:27
  • Try stepping through the code slowly in debug mode, often that will expose if there are timing issues. If you get the same exception then there is probably something in the DOM that it doesn't like. – Brian Kampling Jun 01 '16 at 20:01
0

Add a sleep(10) in to make sure everything on the page has loaded first before any user actions are preformed. If that doesn't work also add

driver.manage().window().maximize() at the start of your test to make sure all the page elements is in view.

If that doesn't work its your xpath. Try something like //*[@class="form-group for-sale"]/input

Or use the Firefinder add on in mozilla firefox to check your xpath is valid and exists on the page.

Speedychuck
  • 400
  • 9
  • 29
  • I'm currently already using the .maximize(). Tried to use Sleep(10) and longer but it seems to still believe the element is hidden, so i cant interact with it – Angela Rauws May 26 '16 at 15:30
  • Ok is the frontend using a framework such as react.js or anything like that which hides class="form-group for-sale"]/input until another element is activated like a button? – Speedychuck May 26 '16 at 16:02
0

Selenium is good at scrolling down to view an item, but when it comes to Scrolling back up it's a PiA, and usually throws that exception. I usually just do something like

element.SendKeys(Keys.Home);
Thread.Sleep(100);
  • I don't think i need to scroll down as the element is visible, near the top of the page, upon page load. The Thread.Sleep doesnt seem to be helping – Angela Rauws May 26 '16 at 15:31