Running Internet Explorer with selenium WebDriver.quit(); does not work - java

I am running the following code and the browser does not close.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class _getPageIE {
public static void main(String[] args) throws InterruptedException {
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
System.setProperty("webdriver.ie.driver", "C:\\WebDriver\\IEDriverServer.exe");
WebDriver ieDriver = new InternetExplorerDriver(capabilities);
ieDriver.manage().window().maximize();
ieDriver.get("http://google.com");
ieDriver.quit();
System.out.println("end");
}
}
The Browser opens, then is maximized and the Google page is displayed. Then the System.out.printlin is executed and the program ends, but the browser remains open.
I am running Eclipse with Selenium 2.44 on Windows 8.1 64 bit with the 64 bit IEDriverServer.exe.
The Console output is as follows.
Started InternetExplorerDriver server (64-bit)
2.44.0.0
Listening on port 46733
end
Any help is appreciated.

Related

Selenium chromedriver does not close properly

I'm using chromedriver and Java to run automatic web tests. To be able to use extensions in Chrome I'm using my existing browser profile. Since then I'm experiencing following:
run a selenium test with green result
open Chrome manualy (or run some test)
get error message "chrome application did not close properly"
I'm closing browser and the driver with this:
#AfterClass public static void tearDownClass() {driver.quit();}
I've tried:
#AfterClass public static void tearDownClass() {driver.close();}
but this closes just browser, not the driver.
After some attempts to fix I simulate pressing CTRL+SHIFT+Q:
package SSO_CWP_APPROVAL;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import org.openqa.selenium.WebDriver;
public class Keyboard_events {
public static WebDriver driver;
public Keyboard_events(WebDriver driver) {Keyboard_events.driver = driver;}
public void ctrl_shift_q() throws AWTException, InterruptedException {
Robot rob = new Robot();
rob.keyPress(KeyEvent.VK_CONTROL);
rob.keyPress(KeyEvent.VK_SHIFT);
rob.keyPress(KeyEvent.VK_Q);
rob.keyRelease(KeyEvent.VK_CONTROL);
rob.keyRelease(KeyEvent.VK_SHIFT);
rob.keyRelease(KeyEvent.VK_Q);
Thread.sleep(1000);
}
}
The sleep is in this case neccessary. Sleeping less time and get the error again.
#AfterClass public static void tearDownClass() throws AWTException, InterruptedException {K_events.ctrl_shift_q();driver.quit();}
binaries:
Version: Oxygen.3a Release (4.7.3a)
Build id: 20180405-1200
chromedriver.exe 2.42
JDK 8u151
Chrome 69.0.3497.100
Is there any better way how to close browser and the driver?
It was propably bug in Google Chrome 69. In version 70 and 71 works driver.close();driver.quit(); just fine.

selenium won't get URL?

this my code open fire fox and get google
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class auto {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "//root//Desktop//jarselenium//geckodriver-v0.20.1-linux64/geckodriver");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
//driver.get("https://www.easybooking.lk/login");
//driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
driver.get("https://www.google.com");
}
}
but when i run this code selenium open fire fox but wont get url im running this code in linux
As per the current implementation of Selenium v3.11.0, GeckoDriver 0.20.1 I don't see any major issue in your code block perhaps the trace logs would have helped us to understand your issue better. Having said that you need to follow the below mentioned steps :
As you are using Linux based System you need to pass the absolute path of the GeckoDriver within single forward slashes i.e. / as follows :
System.setProperty("webdriver.gecko.driver", "/root/Desktop/jarselenium/geckodriver-v0.20.1-linux64/geckodriver");
As GeckoDriver opens Firefox Browser client in maximized mode you need to omit the line of code :
driver.manage().window().maximize();

The driver executable does not exist: Selenium Firefox

I've been struggling with this for the past few hours. I'm trying to install Selenium web driver and have been running into a bunch of errors which prevent me from running the test page. I'm pretty sure my most recent issue is with this code:
public static void main(String[] args) throws InterruptedException{
System.setProperty("webdriver.gecko.driver","C:/Users/theone/Downloads/geckodriver 2.exe");
Would really appreciate any feedback on second steps!
package automationFramework;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirstTestCase {
public static void main(String[] args) throws InterruptedException{
System.setProperty("webdriver.gecko.driver","C:/Users/theone/Downloads/geckodriver 2.exe");
// Create a new instance of the Firefox driver
WebDriver driver = new FirefoxDriver();
//Launch the Online Store Website
driver.get("http://www.store.demoqa.com");
// Print a Log In message to the screen
System.out.println("Successfully opened the website www.Store.Demoqa.com");
//Wait for 5 Sec
Thread.sleep(5);
// Close the driver
driver.quit();
}
}
You can setup Selenium with GeckoDriver either with webdriver.gecko.driver property or using environment properties. It would be good if you the latest version of Firefox, GeckoDriver and Selenium 3.0
Check out this article which provides setup using both these ways -
http://automationtestinghub.com/selenium-3-0-launch-firefox-with-geckodriver/
C:/Users/theone/Downloads/geckodriver 2.exe
There's a space in the path, it may work if you rename your file geckodriver2.exe.

Unable to go for next Annotation of selenium browser automation with simple java codes

The thing what I wanted to do was automate the Firefox browser for search an item in the search bar. My java codes are as follows.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FlipkartTest {
public static void main(String[] args) {
CharSequence[] cs = {"Dell"};
//CharSequence[] d = String[]{"Dell"};
//String s = toString();
WebDriver driver = new FirefoxDriver();
driver.get("http://www.flipkart.com");
driver.findElement(By.id("fk-top-search-box")).sendKeys(cs);
driver.findElement(By.xpath("//input[#value=Search]")).click();
}
}
After debug or run the code a new Firefox window is appeared, But when click on next Annotation button, Nothing was happened. it doesn't go for next step such as opens the Flipcart.com site or searches the word.
After run the code, The console display a list. I found this line from it.
Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms.
So how I fix this problem?
As been answered here the problem is in mismatch between selenium and Firefox. Updating them to the latest version should solve the problem.
I recommend you to first set the properties of the Firefox driver and then create an instance of it. Something like this -
Webdriver driver=null;
System.setProperty("webdriver.firefox.driver"."//your firefox driver path");
driver=new FirefoxDriver();
Also try with ChromeDriver and InternetExplorerDriver and check if the problem still persists.

Selenium Webdriver remote setup

I have the selenium-server-standalone.jar running on my local machine, and the tests I want to run compiled on my remote machine, but I have no idea how I make the tests connect to the machine that will run the browser. Any help appreciated.
Update:
On my local machine (the one I will be running the browser on) I ran
java -jar selenium-server-standalone-2.25.0.jar -mode hub
on my remote machine (that I will run the tests from) I ran
java -jar selenium-server-standalone-2.25.0.jar -role webDriver -hub http://**My ip*:4444
my code contains the following:
#Before
public void setUp() throws Exception {
DesiredCapabilities capability = DesiredCapabilities.firefox();
driver = new RemoteWebDriver(new URL("http://**My ip**:4444/wd/hub"),
capability);
baseUrl = "http://phy05:8080";
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.manage().window().setSize(new Dimension(1920, 1080));
I am using Linux and my tests are written in Java
well. That's not a problem. I'd like to share how i resolved this issue.
I got VM (virtual machine) with jdk installed and selenium server running on VM. VM has IP:
192.168.4.52
I connected to it through(RDC-remote desktop connection). Installed needed browser on it(firefox 15). Open browser. Disabled all the updates and other pop ups.
I've got selenium tests pack on my local machine. And I run them on my VM.
Selenium setup is following:
import com.google.common.base.Function;
import com.thoughtworks.selenium.SeleneseTestBase;
import junit.framework.Assert;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
public class BaseSeleniumTest extends SeleneseTestBase {
static WebDriver driver;
#Value("login.base.url")
private String loginBaseUrl;
#BeforeClass
public static void firefoxSetUp() throws MalformedURLException {
// DesiredCapabilities capability = DesiredCapabilities.firefox();
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
driver = new RemoteWebDriver(new URL("http://192.168.4.52:4444/wd/hub"), capability);
// driver = new FirefoxDriver(); //for local check
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.manage().window().setSize(new Dimension(1920, 1080));
}
#Before
public void openFiretox() throws IOException {
driver.get(propertyKeysLoader("login.base.url"));
}
#AfterClass
public static void closeFirefox(){
driver.quit();
}
.....
this piece of code will run all the selenium tests on remote machine.
in the string driver = new RemoteWebDriver(new URL("http://192.168.4.52:4444/wd/hub"), capability);
you simply should mention IP of your machine and this should work.
Hope this helps you.

Categories

Resources