options.AddArguments(“chrome.switches”, “–disable-extensions”)
var options = new ChromeOptions();options.AddArguments(“chrome.switches”, “–disable-extensions”);var driver = new ChromeDriver(_CHROME_DRIVER_PATH, options);
DevOps | Software Automation | Continuous Integration
options.AddArguments(“chrome.switches”, “–disable-extensions”)
var options = new ChromeOptions();options.AddArguments(“chrome.switches”, “–disable-extensions”);var driver = new ChromeDriver(_CHROME_DRIVER_PATH, options);
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.
Recent task of me is to make the Selenium tests reliable. Functional tests have the following drawback:
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();
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.
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
In order to bypass the untrusted SSL connection error, you will need to:
FirefoxProfile profile = new FirefoxProfile(@”C:UserschuanlAppDataRoaming MozillaFirefoxProfiles qu7su2xj.default”); IWebDriver driver = new FirefoxDriver(profile);
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(“/
Below are the 3 key things which you need to configure in order for Selenium to work in Internet Explorer 8
© 2023 Chuan Chuan Law
Theme by Anders Noren — Up ↑