Internet Explorer is not closing via selenium script with every solution - selenium

I am Not able to close the Internet Explorer via selenium script, I tried every Solution to Kill the IEDriver task and Iexplorer.exe.
I also Tried solution: Internet Explorer 11 does not close after Selenium Test 2 but it still not working for me.
I am Using below,
Selenium 3.4,
IE: 11.1358.14393.0,
InternetExplorerServerDriver: 3.4.0
Below is my code.
import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Tc03_IEDriver_First_use {
public static void main(String[] args) throws Exception {
//Set IEDriver Properties
System.setProperty("webdriver.ie.driver", "D:\\Rohit Bhatkar\\Selenium Jars\\IEDriverServer_x64_3.4.0\\IEDriverServer.exe");
//Set desired Capabilities of IE. these statements removes an zoomsetting error.
//You Can set Zoom mannually as, Go To View Menu on IE > Click On Zoom > Select 100%
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability("ignoreZoomSetting", true);
//Create IEDriver obj, Open Browser, Open URL, Close the Browser
WebDriver obj1= new InternetExplorerDriver(caps);
obj1.manage().window().maximize();
obj1.get("https://www.google.com");
obj1.quit(); //IE not Closing. Steel need to do some work to close the browser
}
}

I would try to first obj1.close() to close the browser window. Then I would use obj1.quit() to quit the webdriver which would close it's terminal window in Windows.

Your code seems to work fine. I tested it and the IE browser closed at the end.
Try obj1.close(); instead of obj1.quit();

Here is the Answer to your Question:
Try these settings for IE 11:
Note: You have to set Zoom Level to 100% for IE to work properly.
System.setProperty("webdriver.ie.driver", "C:\\Utility\\BrowserDrivers\\IEDriverServer.exe");
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability("platform", "WIN8");
cap.setCapability("version", "11");
cap.setCapability("browserName", "internet explorer");
cap.setCapability("ignoreProtectedModeSettings",1);
cap.setCapability("nativeEvents","false");
cap.setCapability("ignoreZoomSetting", true);
cap.setCapability("requireWindowFocus","true");
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
WebDriver driver = new InternetExplorerDriver(cap);
driver.manage().window().maximize();
driver.get("https://google.co.in");
System.out.println(driver.getTitle());
driver.quit();
Let me know if this Answers your Question.

Related

Web page stuck with loading bar while executing the automation script using Selenium?

I'm executing the automation script, in which I am facing loading bar for infinite time on the specific web page.
I have confirmed that issue is not from script side because earlier same scripts are executing fine.
I have applied the solutions as below.
Executing the script in other browsers
Increase wait time
Updated Chrome browser/chromedriver.exe
Currently I'm using below tools/version
Chrome Version: 89.0.4389.82
Chrome driver[Version:ChromeDriver89.0.4389.23]
Java [version: 11]
Selenium WebDriver
Can anyone please provide me the solutions?
Thanks in advance
Try changing the page load strategy to "eager":
This will make Selenium WebDriver to wait until the initial HTML document has been completely loaded and parsed, and discards loading of stylesheets, images and subframes.
When set to eager, Selenium WebDriver waits until DOMContentLoaded event fire is returned.
Example usage:
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;
public class pageLoadStrategy {
public static void main(String[] args) {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
WebDriver driver = new ChromeDriver(chromeOptions);
try {
// Navigate to Url
driver.get("https://google.com");
} finally {
driver.quit();
}
}
}

How to open Chrome browser console through Selenium?

I want to open chrome browser console by pressing keyboard keys Ctrl+Shift+j in selenium webdriver.
I am able to do this action using Robot class but I want this without Robot class. I have used the Actions class and Keys class using sendKeys. But I am unable to open browser console.
Is it chrome browser version issue or OS? Why the browser console is not opening using Action class and Keys class. ?
To open chrome browser console you can use the ChromeOptions class with --auto-open-devtools-for-tabs argument as follows:
Test Configuration:
Selenium: Selenium Standalone Server v3.14.0
ChromeDriver: ChromeDriver 2.46.628402
Chrome: Google Chrome 72.0.3626.96
Code Block:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class A_Chrome_Browser_Console {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("--disable-extensions");
options.addArguments("--auto-open-devtools-for-tabs");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com/");
System.out.println(driver.getTitle());
}
}
Console Output:
Google
Browser Console Snapshot:
You can find a relevant python based discussion in Opening inspect (pressing F12) on Chrome via Selenium

IE browser gets shrunk during execution

I am facing an weird issue. I have a selenium suite to execute on multiple browsers. It works fine of chrome and Firefox. But in case of IE, the web page under test gets shrunk (web page resize) making elements hidden. Hence facing NoSuchElementException.
I have already tried executing on full screen. No help.
Please help in solving this issue.
Thanks,
Praveen
Don't know the exact reason for that, however, suggested workaround would be to implement pre-execution method for your test which would take care of all your browser different configurations. For example, if you are using Java with Selenium and JUnit5, it might be:
#BeforeEach
void beforeTestExecution() {
DesiredCapabilities desiredCapabilities = DesiredCapabilities.internetExplorer();
desiredCapabilities.setCapability(
CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
driver = new InternetExplorerDriver(desiredCapabilities);
// Navigate to URL
driver.get("http://www.yoursite.com");
// Maximize your website window before test.
driver.manage().window().maximize();
}
Or:
#BeforeEach
void configBrowser() {
DesiredCapabilities desiredCapabilities = DesiredCapabilities.internetExplorer();
desiredCapabilities.setCapability(
CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
driver = new InternetExplorerDriver(desiredCapabilities);
// Start Internet Explorer maximized.
driver.manage().window().maximize();
}

Webelement.Click() - Getting exception on Webelement.Click() though it clicks the Element

Meta
OS: Windows
Selenium Version: 2.53.1.0
IDE: Visual Studio 2013
Browser: Internet Explorer 11 version 11.420
I am getting an exception when i tried to click an element on webpage. This happens when a link is clicked and it opens a dialog. Webelement.click() function clicks the element and the modal dialog is opened but Click() takes time to return and finally logs exception as 'The HTTP request to the remote WebDriver server for URL "" timed out after 60 seconds.'
Expected Behavior:
It should click the "Firefox Beta" download button and "IE tool bar" with RUN and SAVE option will appear
Actual Behavior:
It clicks the "Firefox Beta" download button and "IE tool bar" is coming. But downloadElement.Click() waits for 60 seconds and throws exception.
Steps to reproduce:
Below is code snippet:
string url = "https://www.mozilla.org/en-US/firefox/channel/#beta";
try{
IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl(url);
Thread.Sleep(5000);
IWebElement downloadElement = driver.FindElement(By.XPath("//div[#id='download-button-desktop-beta']/ul/li/a/strong"));
Thread.Sleep(5000);
downloadElement.Click();
}catch{
//catch block
}
Try giving this xpath instead of that.
IWebElement downloadElement = driver.FindElement(By.XPath("/html/body/div[2]/div/main/section[1]/div/div/ul/li[1]/a/strong"));
Sometimes their is some problems with IE11 selenium is not able to work as expected. so i use double click instead of click in certain scenarios.
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("/html/body/div[2]/div/main/section[1]/div/div/ul/li[1]/a/strong"))).doubleClick().perform();
try using both, hope it will helps
You can add implicit wait after downloadElement.Click() and wait for modal dialog to load completely.
Try this. It worked for me -
package sbps;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class cvs_signup
{
public static void main(String[] args) {
String url = "https://www.mozilla.org/en-US/firefox/channel/#beta";
try{
WebDriver driver = new InternetExplorerDriver();
driver.get(url);
Thread.sleep(5000);
WebElement downloadElement = driver.findElement(By.xpath("(//a[#href='https://download.mozilla.org/?product=firefox-beta-stub&os=win&lang=en-US'])[last()]"));
Thread.sleep(5000);
downloadElement.click();
}catch(Exception e){
//catch block
}
}
}

Selenium Web Driver firefox not responding

I am using simple selenium example using Web driver classes, but the IE web driver class working fine, but the Firefox is not responding not opening browser and not throwing any error in console.
code is here
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleSearchFF {
public static void main(String args[]){
WebDriver driver=new FirefoxDriver();
System.out.println("Loading Google search page");
driver.get("http://www.google.com");
System.out.println("Google search page loaded fine");
}
}
selenium jar files added to classpath..
\selenium-java-2.13.0\selenium-2.13.0\selenium-java-2.13.0.jar
\selenium-java-client-driver-1.0.1\selenium-java-client-driver.jar
\Selenium Latest\selenium-server-standalone-2.13.0.jar
any jar is missing?
The code works for IE by setting proeprty INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS = true
Downgrade the Firefox version to 8 as Selenium 2.13.0 supports Firefox versions upto 8 only.
For reference check this log.
Instead of downgrading Firefox to 8,
You need to download the geckodriver.exe and set the System.property() by
System.setProperty("webdriver.gecko.driver", "pathTogeckodriver");
before calling WebDriver driver = new FirefoxDriver();