Unable to find element
Meta -
OS: Windows 8.1 Selenium Version: 2.53.0 Browser: IE11 Browser Version: IE 11 64 bit
Expected Behavior -
It's unable to find an element, the code works correctly on both FF and Chrome. This means that element exist on the page.
Actual Behavior -
It throws an exception
Steps to reproduce -
Please run the below code:
package tutorialselenium;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.ie.InternetExplorerDriver; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test;
public class IEIssue { private WebDriver driver; private String baseUrl;
@BeforeClass
public void beforeClass() {
System.setProperty("webdriver.ie.driver",
"C:\\Users\\Anil Tomar\\workspace\\SeleniumWD2Tutorial\\libs\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
baseUrl = "https://www.expedia.com/";
// Maximize the browser's window
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get(baseUrl);
}
@Test
public void searchFlights() throws Exception {
// By id or xpath, it does not work by both
// WebElement element = driver.findElement(By.id("tab-flight-tab"));
WebElement element = driver.findElement(By.xpath("//a[@id='tab-flight-tab']"));
element.click();
}
@AfterClass
public void afterClass() throws Exception {
driver.quit();
}
}
Update @BeforeClass with:
System.setProperty("webdriver.ie.driver",
"C:\\Users\\Anil Tomar\\workspace\\SeleniumWD2Tutorial\\libs\\IEDriverServer.exe");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false);
capabilities.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, false);
capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
capabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);
driver = new InternetExplorerDriver(capabilities);
baseUrl = "https://www.expedia.com/";
// Maximize the browser's window
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get(baseUrl);
i agree with this issue,
Unfortunately it's impossible to use the provided sample to reproduce the issue, the target page does not contain an element By.xpath("//a[@id='tab-flight-tab']"). If the issue is still actual please request reopening it with an updated code sample.