I am trying to run some automated tests on IE11 using Selenium Webdriver. Whenever I run my code the URL that IE tries to load is http://--port=38198/
I am trying to simply load Google and return the title, then I will move onto the actual automated testing I intend to do.
Here is a sample of my code so far;
private WebDriver driver;
private String baseUrl;
#Before
public void setUp() throws Exception{
System.setProperty("webdriver.ie.driver", "C:\\Program Files\\Internet Explorer\\iexplore.exe");
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
baseUrl = "http//www.google.com";
driver = new InternetExplorerDriver(cap);
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void test() throws Exception{
driver.get(baseUrl);
System.out.println(driver.getTitle());
//driver.navigate().to(baseUrl);
}
Ever time I run my code it always opens the same URL - http://--port=
From my code I can't see where I have gone wrong. I changed the security settings on IE to medium and disabled protected mode (I have tried it with protected mode turned on and still no luck). I have also downloaded and installed Microsofts IE11 web driver.
I am totally mystified by this, can someone give me any insight into this...
It seems that you are using your native Windows IE?
You have to download the IE WebDriver from https://code.google.com/p/selenium/wiki/InternetExplorerDriver and your webdriver.ie.driver property needs the path to the downloaded IEDriverServer.exe
Please try and report if that solves your problem. If not I will change my chrome WebDriver to the IE and try it myself :)
Related
I'm doing an automated test, using Java (8), Selenium (4) and Chromedriver (98.0).
The test is for a site that requires to login with different third party accounts, one of them being GitLab.Unfortunately the test always gets stuck while trying to access Gitlab's login page, on the "Checking your browser before accessing gitlab.com" part. If I pause the test on this step and duplicate the tab manually, the newly opened tab will be able to enter and then the first one will be also able to do it (probably because at that point finally has a valid cookie).I've tried out different solutions but with no luck. Currently this is my code:
#Test
public void test() throws MalformedURLException {
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-blink-features=AutomationControlled");
options.addArguments("--start-maximized");
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.setExperimentalOption("useAutomationExtension", false);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
driver.navigate().to("https://gitlab.com/users/sign_in");
new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(60))
.pollingEvery(Duration.ofSeconds(2))
.until(x -> driver.findElements(By.xpath("//*[#data-translate='checking_browser']")).size() == 0);
}
When trying to use undetected_chromedriver, using Python, it worked, but it's a requirement for me to use Java. Is there something similar for Java or is there an extra ChromeOption that I'm missing?
need to download chrome driver https://chromedriver.chromium.org/downloadshttps://chromedriver.chromium.org/downloads
and add this code while setting up driver
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();
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 working on writing an automation script to test a website login. Through Firefox IDE, I have written TestCase steps, it is executing fine. I exported the test case as java code compatible with jUnit 4.
When i try to run the java code via Eclipse (with firefox browser), either it opens Mozilla homepage or blank page or proxy issue (if my machine is connected to company LAN).
I am using Selenium 2.44 and Firefox version 44..
Also i read in some websites saying about compatible version of firefox with selenium web driver. I am confused a lot regarding this.
Please let me know which version of Selenium Web driver, Firefox & Java is preferred..!!!
Adding my java code below
public class Firefox {
private WebDriver driver;
private String PROXY = "proxy address:port";
private String baseUrl;
private boolean acceptNextAlert = true;
#Before
public void setUp() throws Exception {
// Code for setting up Firefox proxy
Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
.setFtpProxy(PROXY)
.setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
driver = new FirefoxDriver(cap);
baseUrl = "url";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testFirefox() throws Exception {
driver.get(baseUrl);
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try {
if ("".equals(driver.findElement(By.id("userId")).getText())) break;
}
catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.id("userId")).sendKeys("user name");
driver.findElement(By.id("pwd")).sendKeys("password");
driver.findElement(By.id("sign-in")).click();
}
}
Latest stable compatible configuration which i've found and I am using it is selenium Webdriver 2.48.2 and Firefox 41.0.2
Download Firefox ESR from https://www.mozilla.org/en-US/firefox/organizations/all/
Its stable version browser of Firefox compatible with Webdriver 2.48.2.
Selenium WebDriver 2.48.2 will not work with FF 44.
The latest Firefox always works with the latest version of Selenium (2.x versions) for all non-native events, such as JavascriptExecutor events, but there are some native events (such as driver.navigate.to() and driver.click() that won't work except with the last known native supported version of Firefox, which was 31.6.0 ESR. It's possible that later versions of ESR will work, but I have not read that anywhere.
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 trying to set Chrome as my browser for testing with Web-Driver and set the chromedriver.exe file properly but I am still getting the following error:
org.openqa.selenium.WebDriverException:
The path to the driver executable must be set by the webdriver.chrome.driver system property;
for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver.
The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list
I have already checked the path of the driver but still i am getting same error.
I don't know where i have made a mistake.
Here is my code:
File file = new File("C:\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
Capability= DesiredCapabilities.chrome();
Capability.setBrowserName("chrome");
Capability.setPlatform(Platform.LINUX);
browser=new RemoteWebDriver(new URL(nodeURL),Capability);
browser.get(webUrl);
Please help me!!
Aditya,
As you said in your last comment that you are trying to access chrome of some other system so based on that you should keep your chrome driver in that system itself.
for example: if you are trying to access linux chrome from windows then you need to put your chrome driver in linux at some place and give permission as 777 and use below code at your windows system.
System.setProperty("webdriver.chrome.driver", "\\var\\www\\Jar\\chromedriver");
Capability= DesiredCapabilities.chrome(); Capability.setPlatform(org.openqa.selenium.Platform.ANY);
browser=new RemoteWebDriver(new URL(nodeURL),Capability);
This is working code of my system.
I'm using this since the begin and it always work. =)
System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
For Mac -Chrome browser
public class MultipleBrowser {
public WebDriver driver= null;
String browser="mozilla";
String url="https://www.omnicard.com";
#BeforeMethod
public void LaunchBrowser() {
if(browser.equalsIgnoreCase("mozilla"))
driver= new FirefoxDriver();
else if(browser.equalsIgnoreCase("safari"))
driver= new SafariDriver();
else if(browser.equalsIgnoreCase("chrome"))
System.setProperty("webdriver.chrome.driver","/Users/mhossain/Desktop/chromedriver");
driver= new ChromeDriver();
driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
driver.navigate().to(url);
//driver.manage().deleteAllCookies();
}
It was giving Illegal Exception.
My workaround with code:
public void dofirst(){
System.setProperty("webdriver.chrome.driver","D:\\Softwares\\selenium\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.facebook.com");
}
Mac OS:
You have to install ChromeDriver first:
brew cask install chromedriver
It will be copied to /usr/local/bin/chromedriver. Then you can use it in java code classes.
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver","Absolute path of Chrome driver");
driver =new ChromeDriver();
baseUrl = "URL/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}