DevOps | Software Automation | Continuous Integration

Tag: Selenium exception

Chrome Driver Bug – Disable Developer Mode Extensions Pop Up

There is a bug in the Chrome Driver where you will get a Disable Developer Mode Extensions pop up occasionally in your test.
I still cannot work out why we started to get this problem as we have not upgraded the version of the Chrome driver.
The even more odd thing is that I found out that the pop up appears on bigger pages with lots of data and by cleaning up the data is able to temporarily get rid of the pop up.
However, the proper solution is to have the following line in your code:

options.AddArguments(“chrome.switches”, “–disable-extensions”)

So, the final code looks like this:
    var options = new ChromeOptions();
    options.AddArguments(“chrome.switches”, “–disable-extensions”);
    var driver = new ChromeDriver(_CHROME_DRIVER_PATH, options);
However, you might get this message on the browser while you run your tests:
But don’t panic, because everything will work perfectly without the pop up message!

Selenium Webdriver: How To Deal With Pages With Complex Ajax Calls

If the web page that you testing consists of complex ajax calls, you may be facing the problem where the tests will fail occasionally due to incomplete ajax calls returned.

To deal with this problem, I have added a function in my test:

driver.WaitForAjaxLoadComplete();

And what the function does is:

 public static void WaitForAjaxLoadComplete(this IWebDriver driver   {

            IWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60.00));

            wait.Until(driver1 => (bool)(driver1 as IJavaScriptExecutor).ExecuteScript(“return jQuery.active == 0”));

        }

Basically, it tells Selenium to wait until all jQuery calls are completed before the next actions.

Selenium Webdriver: How To Deal With “WebDriverException: Element is not clickable at point (x, y). Other element would receive the click:”

Recent task of me is to make the Selenium tests reliable. Functional tests have the following drawback:

  • Update of tests are required when DOM changes
  • Selenium work differently when you use different web drivers
           Eg: A checkbox is visible when you use Firefox, but hidden in Google driver
  • Depending on how the web page is constructed, you may get inconsistent behavior with the tests.
          Eg: Element is clickable now but not when you run it again
In my previous post, I talked about the “Stale element exception” which we have to find some other creative ways to get around. Please note that there are multiple ways to get around that problem which I will share with everybody in my future post.
Today, I am going to talk about a specific problem I have when using the Google Driver –
WebDriverException: Element is not clickable at point (x, y). Other element would receive the click
 
 
The solution is:
Instead of using the usual Click method:

driver.FindElement(By.Id(“id”)).Click;

We use the Actions method:

IWenElement element=driver.FindElement(By.Id(“id”));

Actions actions = new Actions (driver);

actions.MoveToElement(element).Click().Perform();

Selenium Webdriver: How To Deal With “Element Is No Longer Attached To The DOM”

I got an inconsistent scenario where sometimes I got the error “Element Is No Longer Attached To The DOM”.

To deal with this I have added the following code while accessing the element:

 int count = 0;
            while (count < 5)
            {
                try
                {
                    IWebElement textFound = driver.FindElement(By.LinkText(text));
                    textFound.Click();
                }
                catch (StaleElementReferenceException e)
                {
                    e.ToString();
                    Console.WriteLine(“Trying to recover from stale element:” + e.Message);
                    count = count + 1;
                }
                count = count + 5;
            }

Thus, instead of failing straightaway, the test will attempt a few times to click the element, or else exception will be caught to allow the test to fail gracefully.

How To Bypass Untrusted SSL Connection II

I guess I have blogged about how to bypass Untrusted SSL Connection before by using your local computer’s FireFox with stored certificate. However, there are cases when by doing this itself is not sufficient.

Below is what you can do besides that:

1. Enter “about:config” in the address bar of your FireFox
2. Enter the following settings (https://pusso is the website I want to bypass)

3. Use the following code in your Selenium code

FirefoxProfile profile = new FirefoxProfile(@”pathtolocalfirefoxprofile”);
profile.SetPreference(“network.http.phishy-userpass-length”, 255);
profile.SetPreference(“network.automatic-ntlm-auth.trusted-uris”, “pusso”);

Selenium – How To Bypass Untrusted SSL Connection

In order to bypass the untrusted SSL connection error, you will need to:

  • Launch the browser from desktop
  • Manually adds the exception to bypass the untrusted SSL message
  • Declare the web driver to use the desktop browser’s profile instead of Selenium’s default profile
FirefoxProfile profile = new FirefoxProfile(@”C:UserschuanlAppDataRoaming MozillaFirefoxProfilesqu7su2xj.default”);
IWebDriver driver = new FirefoxDriver(profile); 
  • Once that is done, when you run Selenium, you will not get the untrusted SSL message again.

IE Does Not Recognise Complex XPath

You may need different code for FireFox and IE. This is because IE does not recognise complex XPath expressions.

For eg:

This will work in FF

driver.FindElement(By.XPath(“/html/body[@id=’ctl00__objBodyTag’]/form[@id=’aspnetForm’]/div[@id=’__Page’]/div[@id=’page’]/div[@id=”]/div/div/div/div[@id=’expandPanelsPersonalDetails’]/div[11]/img[1]”)).Click(); 

In IE it needs to be simplified to:

driver.FindElement(By.XPath(“//div[@id=’expandPanelsPersonalDetails’]/div[11]/img[1]”)).Click();

 

Getting Selenium To Work In Internet Explorer 8

Below are the 3 key things which you need to configure in order for Selenium to work in Internet Explorer 8

  • Tools->Internet Options->Security tab
Set the security level for all zones to high. This is due to all zones have to be on the same level and Restricted Sites can only be set to high.
  • Zoom level to be 100%
  • Tools->Internet Options->Security tab->Custom level->Scripting
Enable Active Scripting. This is required in order for JavaScript to work.

  • Install the correct version of InternetExplorerDriver – depending on how many bits is your machine

© 2023 Chuan Chuan Law

Theme by Anders NorenUp ↑