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.
Related
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.
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();
Inside main method if I write WebDriver driver = new FirefoxDriver(); and execute the class how does the browser gets open automatically
public class Web{
public Static void main(String[] args){
WebDriver driver = new FirefoxDriver();
}
}
Firefox driver is included in the selenium-server-stanalone.jar available in the downloads. The driver comes in the form of an xpi (firefox extension) which is added to the firefox profile when you start a new instance of FirefoxDriver.
You can read up more on the Firefox Driver here.
If I misunderstood the question and you want to know how to open a browser and go to a URL, the below example will open the Firefox browser and go to http://www.google.com/
public class Web{
public Static void main(String[] args){
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
}
}
Selenium has quite extensive documentation on WebDriver available here. I suggest you read the documentation to get to know Selenium better!
I am trying to run a portion of code in Google Chrome and the rest in Firefox
public class flip
{
static WebDriver driver = new FirefoxDriver(); // starting firefox
public static void main(String[] args) throws IOException, InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:/chromedriver.exe");
WebDriver driver1 = new ChromeDriver();
driver1.get("website1");
driver1.findElement(By.id("id_username")).sendKeys("username");
driver1.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver1.findElement(By.id("id_password")).sendKeys("password");
System.out.print("logged in");
driver1.close();
driver.get("website-2"); // in firefox
}
}
I am getting following error (when program need to switch browsers).
Both browsers are opening but unable to drive.
Exception in thread "main" org.openqa.selenium.WebDriverException:
f.QueryInterface is not a function
Command duration or timeout: 60.03 seconds
Can any one help me where I made mistake ??
(firefox webdriver must be a static..)
put http:// on starting of your web address of your firefox driver. it is obligation in that selenium version.
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.