2

I'm using C# Selenium.WebDriver.2.44.0 On some 3rd party site I'm trying to press an element and get this:

var myWebElement = Driver.FindElement(By.XPath("//a[.=' some value']            
myWebElement.Click();

I get the element and on click I get this:

{"element not visible\n  (Session info: chrome=39.0.2171.95)\n  (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)"}

The item is within some sub menu revealing after I successfully press the parent menu. Also put 5 seconds sleep to be safe that the accordion is well seen (and it is well seen in my eyes).

Question - on 3rd party site how can I force the click on this item?

user1025852
  • 2,684
  • 11
  • 36
  • 58
  • possible duplicate of [selenium webdriver: org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with](http://stackoverflow.com/questions/12082946/selenium-webdriver-org-openqa-selenium-elementnotvisibleexception-element-is-n) – Richard Schneider Jan 16 '15 at 19:50

4 Answers4

0

You could try bringing it to the top by changing the z-index with driver.execute_script().

Attila Szasz
  • 3,033
  • 3
  • 25
  • 39
0

You could use the inbuilt functions and WebDriver waits

var myWebElement = Driver.FindElement(By.XPath("//a[.=' some value']
WebDriverWait wait = new WebDriverWait(Driver.FindElement, TimeSpan.FromSeconds(10));
var element = wait.Until(ExpectedConditions.ElementIsVisible(myWebElement));

Actions action  = new Actions(Driver.FindElement);
action.MoveToElement(element).Perform();

myWebElement.Click();
Jamie Rees
  • 7,973
  • 2
  • 45
  • 83
  • Question is related to **non-visible element** you answer will fail `var element = wait.Until(ExpectedConditions.ElementIsVisible(myWebElement));` – Saifur Jan 16 '15 at 22:11
0

The problem is that Selenium executes actions one after another, but something like "show a sub menu" is lost between actions.

You're likely going to have to use an Actions chain for this:

Actions action = new Actions(Driver);

action.MoveToElement(Driver.FindElement(By(ParentElementSelector)))
    .click()
    .MoveToElement(Driver.FindElement(By.XPath("//a[.=' some value'])))
    .click()
    .Build()
    .Perform();

This will move to the parent element, click, then move to the element you wish to find, then click. It will perform all of these as one action, which should be able to click the sub menu element.

Richard
  • 8,961
  • 3
  • 38
  • 47
  • mmm, almost there - it did the accordion thing and now the second item is seen - but didn't do the "second click" - however no exception thrown... – user1025852 Jan 17 '15 at 17:53
  • If you link to the third party site, I can take a look at it later and possibly come up with a solution. – Richard Jan 19 '15 at 16:20
-1

When an element is not visible u can try this...It works for me

IWebElement WEHiddenID = driver.FindElement(By.Id(""));
WEHiddenID.SendKeys(OpenQA.Selenium.Keys.Enter);
QBrute
  • 4,405
  • 6
  • 34
  • 40
Madhu
  • 479
  • 4
  • 10