0

I am using following xpath to click on element using JSExecutor in Selenium webdriver. This works fine in Firefox and chrome but does not work in IE.

Any idea to make this work? After lot of trial and error I have made this work in FF and chrome and have come up with the following XPath.

//*[contains(@class,'ui-select-choices-row') or contains(@id,'ui-select-choices-row')]//*[text()='TextofMyElementToBeclicked'

Additional info: This is a Jquery drop down on an angularJS application. When the user clicks on the drop down //ul is loaded and i am using the above xpath (which is part of //ul) to select the element based on text (using Javascript executor click). I used JS executor because, click() function in selenium simply could not click on the drop down element.

I am clicking element using below.

WebElement element = driver.findElement(By.xpath("YourNumbersXpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
    enter code here
Mike
  • 899
  • 9
  • 27
  • 45
  • I think that you can find the solution [Here](http://stackoverflow.com/questions/15252837/selenium-javascriptexecutor-on-ie9-results-in-element-was-not-scrolled-into-the) or [Here](http://stackoverflow.com/questions/20138761/how-to-select-a-dropdown-value-in-selenium-webdriver-using-java) – ImLearning Mar 20 '16 at 21:22

2 Answers2

1

I successfully tested your XPath with IE11, so it's not an issue related to IE. It's most likely a timing issue. First click on the drop button, then wait for the targeted element to appear and finally click on it:

WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 30);
driver.get("...");

// move the cursor to the menu Product
WebElement element = driver.findElement(By.xpath("drop down button")).click();
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("drop down item"))).click();
Florent B.
  • 41,537
  • 7
  • 86
  • 101
  • Have tried this and also tried elemntToBevisible.. Both fail with error not able to find element.. Strangely this fails only in IE 11. – Mike Mar 20 '16 at 23:07
  • No.. It simply says that it cannot find the xpath.. It waits foe the default timrout and throws the error.. – Mike Mar 20 '16 at 23:14
  • Can you provide some HTML from IE? – Florent B. Mar 20 '16 at 23:15
  • unfortunately I cannot provide it as I work for a financial customer and we have strict security guidelines not to share details outside.. – Mike Mar 20 '16 at 23:17
  • I am just thinking if I should get all the descendants from the root element (post click) and match it with text and click the element... – Mike Mar 20 '16 at 23:18
  • try with some simple xpath like //*[contains(.,'TextofMyElementToBeclicked')] – Florent B. Mar 20 '16 at 23:21
  • It could be that the document is loaded differently in IE. Anyway, without being able to look at it, there is nothing much I can do to help. – Florent B. Mar 20 '16 at 23:22
0

IE11 seems to struggle with contains(@class and possibly also the contains(@id. Try using alternative solutions like starts-with.