I am using Selenium Webdriver(Java), i want to use IE driver for my testing, however i come up with the problem, can anyone help me out of this please, The script which are running fine in firefox fails to run in IE, I am just opening a google page and searching some word but my code only opens the google page write the keyword but unable to hit the serch button on google page using IEdriver, after too much google i found one thimg that when IE browser get opens it will opened in IE8 Compatibility view and due to this its attributes like id, name get changed as compared to FF, but when i changes this to IE8 view manually the properties are same as FF,(Press F12 key on keyboard open developers tool on IE) So can anyone please let me know how to overcome this or how to open the IE browser in IE8 mode, or anyone knows any different solution of using IE for selenium webdriver.
My code is as follows
package backOffice;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName;
import bsh.ParseException;
public class Time
{
private WebDriver driver;
private String baseUrl= "http://www.google.co.in/";
public static void main(String args[]) throws InterruptedException
{
Time tm=new Time();
tm.trial();
}
private void trial() throws InterruptedException
{
File file = new File("C:/Documents and Settings/Administrator/Desktop/32- bit_IEDriverServer_Win32_2.31.0/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
DesiredCapabilities caps = DesiredCapabilities.internetExplorer(); caps.setCapability("ignoreZoomSetting", true);
driver=new InternetExplorerDriver(caps);
driver.get(baseUrl + "/");
driver.findElement(By.id("gbqfq")).clear();
driver.findElement(By.id("gbqfq")).sendKeys("harshal kakade");
driver.findElement(By.id("gbqfb")).click();
driver.findElement(By.linkText("Harshal Kakade - India | LinkedIn")).click ();
}
}
Thanks,
Harshal.
try to look at the internet options -> security and uncheck "Enable Protected Mode". Probably there is the problem.
Related
Am trying to take the complete page screenshot both horizontally and vertically using Firefox gecko driver and aShot Library.
However, the results are not as expected. Take a look:
driver.get("https://google.com");
Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
ImageIO.write(fpScreenshot.getImage(),"JPEG",new File("FullPageScreenshot.jpg"));
Looked into a lot of variants but nothing is working. Interestingly, when I try using old firefox version (46), I am able to take full screenshot without any third party library. Am trying to use latest firefox and have full screenshot functionality.
Any help?
Try:
Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(ShootingStrategies.scaling(1.75f), 1000)).takeScreenshot(driver);
where 1.75f is device pixel ratio (you can run window.devicePixelRatio; in browser console to find it).
If it's still not capturing full screen, change it to 2f
While working with Selenium Java Client v3.12.0, ChromeDriver v2.40, Chrome v 67.0 using ashot-1.4.4.jar here is an example to take the complete page screenshot both horizontally and vertically using ChromeDriver and aShot Library of the url https://jquery.com/:
Code Block:
import java.io.File;
import javax.imageio.ImageIO;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;
public class ashot_CompletePage {
public static void main(String[] args) throws Exception {
System.setProperty("god.bless.you", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("https://jquery.com/");
new WebDriverWait(driver, 20).until(ExpectedConditions.titleContains("jQuery"));
Screenshot myScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(100)).takeScreenshot(driver);
ImageIO.write(myScreenshot.getImage(),"PNG",new File("./Screenshots/elementScreenshot.png"));
driver.quit();
}
}
Screenshots:
Reference
You can find a detailed discussion in How to take screenshot with Selenium WebDriver
This is another question about Selenium and clicking. I have been struggling for about two days and can't get it to work - I have tried the answers in the internet and now I need a concerted effort. Thanks in Advance!!
I am working on the following site http://144.76.109.38/peTEST - this might help if you want to retrace my steps.
I am trying to fill out the login form, and then click on Login and see the answer page.
Here is my code:
import java.io.File;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.Writer;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.Select;
public class toJava {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","/home/tallen/RTI/lib/geckodriver/geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("http:144.76.109.38/peTEST");
File SF2 = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try{
FileUtils.copyFile(SF2, new File("./out-004.png"));
}catch(IOException ioe){
System.out.println("There was an IO error");
}
driver.findElement(By.id("user_login_name")).click();
WebElement WE4 = driver.findElement(By.id("user_login_name"));
WE4.sendKeys("Superuser");
driver.findElement(By.id("user_password")).click();
WebElement WE6 = driver.findElement(By.id("user_password"));
WE6.sendKeys("Jkerouac1!");
WebElement WE7 = driver.findElement(By.xpath(".//*[#type='button'][#onclick='login()'][#value='Login']"));
WE7.sendKeys(Keys.ENTER);
File SF8 = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try{
FileUtils.copyFile(SF8, new File("./out-005.png"));
}catch(IOException ioe){
System.out.println("There was an IO error");
}
driver.quit();
}
}
So basically I am opening up the page, taking a screenshot entering the user name and password, clicking Login and then taking another screenshot.
The compile and the run on this are clean - that is no exceptions and no problems. I even get two screenshots. The first screenshot shows the login page - with no data entered. The second screenshot shows the login page filled, the button I want to click marked, but not the "welcome Page" that you would get if you successfully log in. That the screenshot shows the button marked, I know that I have found the element. I have give the login info in the script, in case you want to try it out with Selenium first.
Why is the login button not being "clicked." I have tried click, perform, etc. to no avail. I have even tried putting in implicit waits - still nothing.
I have tried to Advanced Usage Interactions - and still nothing.
I am pretty new to Selenium and Java and am hoping that it is just something stupid that I am overlooking. But after looking through the Web, the solutions there are just not helping.
I am working on Debian-70-Wheezy-64-LAMP
My Selenium Libraries are from client-combined-3.0.1-nodeps.jar
My Geckodriver is v0.11.1-linux64
Thanks for the Help!!!
Hi, I don't know if it can cause a problem but anyway for the login button I would use WE7.click(); I just think that it's easier to understand what you're trying to do with the element.
I've been working with the GeckoDriver for a while and talking with some experienced people in the area and they told me that Gecko has many problems that are not fixed yet.
They always recommended me not to use GeckoDriver because it seems to fail very often and told me to use FirefoxDriver instead.
To try it this way, and this is important, you'll just need to keep working with an older version of Firefox as the version 46 that is compatible with FirefoxDriver (that version worked for me and you can download it from places like this) and avoid using GeckoDriver.
Also the version 47 seems to work with the FirefoxDriver as I've found here.
Remember: When you install one of these previous versions of Firefox, don't forget to go to settings and disable the automatic updates and background updates because if you don't do this, you'll end soon again with the latest version that requires GeckoDriver.
In addition you can try some validation as the following:
if(WE7.isDisplayed() && WE7.isEnabled()){
WE7.click();
}
This kind of validations would help in case that the page isn't fully loaded at the moment that you're trying to take action over the web element. If the element is not ready, you will click it without errors but it just won't work
Hope this works for you too!
I’m trying to use Selenium WebDriver with Eclipse and JUnit and a Firefox browser to do a series of Link tests. The trouble I’m having is the Firefox browser is opening some links in a new Window. Note: these are not Alerts.
I have the browser set to open all links in the same window, and if I navigate to the chosen links manually it does what it’s supposed to do. These are the settings of the default browser at present.
browser.link.open_newwindow; 1
browser.link.open_newwindow.disabled_in_fullscreen; true
browser.link.open_newwindow.override.external: 1
browser.link.open_newwindow.restriction; 2
When I run the same thing in Eclipse as a JUnit test from Eclipse the link opens up in a new window!
I commented out driver.close() and checked the browser that Eclipse was using and all the settings are different. There is even another setting that isn’t in my browser.
browser.link.open_newwindow; 2
browser.link.open_newwindow.disabled_in_fullscreen; false
browser.link.open_newwindow.override.external: -1
browser.link.open_newwindow.restriction; 2
browser.link.open_external 2
If I use a profile or force it to use the default profile it the browser it uses has these settings.
browser.link.open_newwindow; 2
browser.link.open_newwindow.disabled_in_fullscreen; true
browser.link.open_newwindow.override.external: 1
browser.link.open_newwindow.restriction; 2
browser.link.open_external 2
From reading previous posts I was of the understanding that Eclipse/Selenium/JUnit would use the default browser installed on my PC. Or at least the default browser profile
My Code:
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class Pro2 {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception {
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("default");
driver = new FirefoxDriver(ffprofile);
// driver = new FirefoxDriver();
baseUrl = "https://www.google.ie/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
My questions are:
Is it using a different driver(or driver profile)?
If so how do I set the config settings so that all links open in the current window?
You can modify firefox profile before you use it in your tests by calling SetPreference method of the FirefoxProfile class:
ffprofile.SetPreference("browser.link.open_newwindow", "1");
I'm trying to made some tests with selenium api on my android device. I've already did the tests in desktop with success, but i'm facing some troubles to make the same program on android.
I created an android project using eclipse IDE, and did the download of selenium here:
http://www.seleniumhq.org/download/ (Java Option)
After, i did the download of the selendroid:
http://selendroid.io/
i've tried to include all these .jar files but when i try to create some AndroidDriver object, my IDE dont recognize this type.
My Class:
package com.example.mobile;
import junit.framework.TestCase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.mobile.*;
public class OneTeste extends TestCase {
public void testGoogle() throws Exception {
WebDriver driver = new AndroidDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
Tried using Selenium with the SafariWebDriver.
Using the jars
selenium-server-standalone-2.33.0.jar - to run the Jetty Server
java -jar ./lib/selenium-server-standalone-2.33.0.jar
selenium-java-2.33.0.jar
(I didn't use Maven to setup project - just downloaded the jars, and compiled with javac)
javac -s ./src -cp ./classes:./lib/selenium-java-2.33.0.jar:./lib/selenium-server-standalone-2.33.0.jar ./src/jgf/Selenium2Example.java -d ./classes
Wrote a class which is more or less a copy/paste of the Selenium2Example, but used SafariWebDriver instead of the FirefoxWebDriver
But when the code executes, I get the message in the Safari Web Browser (using Snow Leopard with Safari 5.1.9 (6534.59.8)).
Unable to establish a connection with the SafariDriver
Any ideas on how to solve this?
BTW: I'm not using a Safari Extension compiled from source with certificate by signing up as an Apple Developer - I think that applied to earlier jar versions.
Here is the code
package jgf;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Selenium2Example {
public static void main(String[] args) {
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
//WebDriver driver = new FirefoxDriver();
WebDriver driver = new SafariDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Alternatively the same thing can be done like this
// driver.navigate().to("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
});
// Should see: "cheese! - Google Search"
System.out.println("Page title is: " + driver.getTitle());
//Close the browser
driver.quit();
}
}
I was having the same issue with 2.34, so I went back to 2.31 and all seems well, not getting the 'unable to establish a connection' error with safari.
Consider the OS Windows.
Prerequisite: Install Safari on Windows
Go to http://docs.seleniumhq.org/download/
Scroll down -> Go to the section "SafariDriver" and download "SafariDriver.safariextz"
Double click on "SafariDriver.safariextz" (previously downloaded)
Safari would open with a pop up containing "Install" button -> Click Install button
Now go to Preferences of Safari and you would see WebDriver (in my case WebDriver 2.48.0) is installed (Enable WebDriver checkbox is checked))
It's now time to instantiate SafariDriver and get the desired URL as below:
WebDriver driver = new SafariDriver();
driver.get("https://www.packtpub.com/web-development/mastering-selenium-testing-tools-video");