Selenium IE WebDriver only works while debugging
There are a couple of facts which you may have to consider as follows :
First of all:
public void waitForPageLoaded(WebDriver driver)
looks to me as a pure overhead. There is basically no need to write a separate wrapper function on top of WebDriverWait.
As per the current implementation of WebDriverWait in Selenium v3.8.1 the Constructors are as follows :
WebDriverWait(WebDriver driver, Clock clock, Sleeper sleeper, long timeOutInSeconds, long sleepTimeOut)
WebDriverWait(WebDriver driver, long timeOutInSeconds)
WebDriverWait(WebDriver driver, long timeOutInSeconds, long sleepInMillis)It is pretty much unclear how you have implemented:
WebDriverWait(driver, SeleniumConfigurator.TIME_OUT)
The arguments looks error prone.
Again, the until condition
d -> ((JavascriptExecutor)d).executeScript("return document.readyState").equals("complete")
is a overhead because the Client (i.e. the Web Browser) will never return the control back to the
WebDriver
instance until and unless'document.readyState'
is equal to"complete"
. Once this condition is fulfilled Selenium performs the next line of code. Hence the functionBoolean org.openqa.selenium.support.ui.FluentWait.until(Function<? super WebDriver, Boolean> arg0)
will have no impact.
It's worth to mention that though the Client (i.e. the Web Browser) can return back the control to the WebDriver instance once
'document.readyState' equal to "complete"
is achieved, it doesn't guarantees that all theWebElements
on the new HTML DOM are VISIBLE, INTERACTABLE and CLICKABLE.Finally, to address your main issue, I needed a clarification about the node
xPath = "//*[@id='link-highlighted']/a"
to ensure whether invokingclick()
opens a new tab or url gets redirected. I don't see you handling either of the cases.
Solution
- While dealing with InternetExplorer, keep in mind InternetExplorerDriver runs in a real browser and supports Javascript.
Set the Browser Focus through :
capabilities.setCapability("requireWindowFocus", true);
If
click()
opens a new window, switch() through thewindow_handles
References
You can find a couple of relevant detailed discussions in:
- Do we have any generic function to check if page has completely loaded in Selenium
- Selenium how to manage wait for page load?
Selenium xUnit not working consistently with IE
It appears that this only doesn't work while debugging (stepping through the code). If I just run it it seems to work.
Why is ChromeDriver working in Debug mode but not on release?
Presuming you have installed the NuGet package Selenium.WebDriver.ChromeDriver
. You will find the latest chrome driver in \Selenium.WebDriver.ChromeDriver\driver\win32\chromedriver.exe
select the correct version based on system.
Add the file to your project, then in the file properties select under "Copy to Output Directory" either "Copy Always" or "Copy if Newer".
This question should help
Selenium WebDriver.ChromeDriver Nuget package installed, but not working for MSTest
How to turn off remote debugging to open this site in IE?
From your description, I think you have configured the site in IE mode site list and tried to automate it in IE mode. It's the expected behavior that you see the error message because you're not using the right way to automate IE mode in Edge.
The right way to automate IE mode in Edge is using IE Driver instead of Edge Driver. For the detailed steps, please follow this guide: Use Internet Explorer Driver to automate IE mode in Microsoft Edge.
Selenium Webdriver - Test fails assert if not running in Debug Mode C# visual studio
You probably just need an explicit wait, try this:
public static bool IsInValidLocation(string invalidLocation)
{
By selector = By.XPath("/html/body/header/div/div[4]/div/div/div[2]/div[1]/form/div[2]/span[2]");
// You might want to research how to construct stable xpaths/selctors
new WebDriverWait(driver.Instance, TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementIsVisible(selector));
var ErrorMessage = driver.Instance.FindElement(selector);
bool result = ErrorMessage.Text.Contains(invalidLocation);
return result;
}
The above code will give that message up to 5 seconds to appear, and will throw a timeout exception if it doesn't appear within 5 seconds. You can adjust it to wait longer if needed.
Related Topics
How to Have a Textfield Inside a Label
How to Make Image Appear Randomly Every X Seconds in Java Using Timer
Updating Version Numbers of Modules in a Multi-Module Maven Project
Is Null Check Needed Before Calling Instanceof
How to Manage Rest API Versioning with Spring
Differencebetween A.Getclass() and A.Class in Java
How to Pick an Item by Its Probability
Java: How to Set Precision for Double Value
JPA Hibernate One-To-One Relationship
Java "Lambda Expressions Not Supported at This Language Level"
How to Call Getclass() from a Static Method in Java
Eclipse Kepler for Os X Mavericks Request Java Se 6
Different Types of Thread-Safe Sets in Java
Persistence Unit as Resource_Local or Jta