Mike
Mike

Reputation: 919

Xpath selector not working in IE but working fine in Chrome and Firefox

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

Upvotes: 0

Views: 2560

Answers (2)

Dominic Giallombardo
Dominic Giallombardo

Reputation: 955

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

Upvotes: 0

Florent B.
Florent B.

Reputation: 42538

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

Upvotes: 1

Related Questions