Unable to launch IE browser in selenium webdriver - selenium

I have written a sample code to launch IE browser and load google page.
public class Sample {
public static void main(String[] args)
{
// TODO Auto-generated method stub
System.setProperty("webdriver.ie.driver","H:/IEDriverServer.exe");
WebDriver driver=new InternetExplorerDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.get("http://www.google.com");
}
}
But when I run this script it launches browser and it gets closed immediately (less than 2 sec) without prompting any error and the script wont terminates.
This is what I can see on console screen:
Started InternetExplorerDriver server (32-bit)
2.53.1.0
Listening on port 46974
Only local connections are allowed
Can any one help me on this issue?

Below steps are worked for me, Hope this will work for you as well:
Open internet explorer.
Navigate to Tools->Option
Navigate to Security Tab
Now for all option like Internet,Intranet,Trusted Sites and
Restricted Site enable "Enable Protected" mode check-box.
Set IE zoom level to 100%
Click on Apply and OK
Close the IE browser and run your script

To execute your code in IE need to set some security setting for your browser:
1) open IE
Goto tools-- select internet options-- select security
Set all zones (Internet , local internet,Trusted sites,Restricted sites) to the same protected mode(enabled or disabled is no matter)
2) set the zoom to 100% : In iE browser at top right hand side corner select settings symbol. select zoom . set zoom to 100% (what ever you want like 125,200 etc) close IE.
3) If you want to see the zoom to display on the page:
On the top right hand side of the browser just right click you will get some options , enable the status bar. Then you will be able to see the zoom at the rightside bottom of the page.

try:
public static void main(String[] args)
{
try
{
string path = #"H:\IEDriverServer.exe";
WebDriver driver = new InternetExplorerDriver(path);
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://www.google.com");
}
catch(Exception ex)
{
}
}

If your IE version is 11, There are following steps to resolve it :-
Registry entries for 32 and 64 bit.
create a DWORD value with the name "iexplore.exe" and the
value of 0 in the following key
for 32-bit Windows :- HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
for 64-bit Windows :- HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
Adjusted "Protected Mode" to be the same for all security zones by navigating through Settings -> Internet Options -> Security
Unchek "Enable Protected Mode" for all zones
Even rebooted.
If still getting the problem Add domain to list of "Trusted Sites" for i.e. in "Internet Options" (https to trusted sites, and http to local intranet).
Hope it will help you..:)

package tests;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Sample {
public static void main(String[] args) {
System.setProperty("webdriver.ie.driver","C:\\Automation Workspace\\ComplianceDashboardProject\\Vendor\\IEDriverServer.exe");
WebDriver driver=new InternetExplorerDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.get("http://www.google.com");
driver.quit();
}
}
I did the above and got it to work. Maybe try moving your driver file to another location to make sure there isn't some security issue.

I completely agree with sandeep's solution along with that for setting zoom level to 100% permanently i am adding few code lines as i faced issue to set this.
These are the code lines i found after i browsed for the zoom level 100% error:
System.setProperty("webdriver.ie.driver", "C:/Drivers/IEDriverServer.exe");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability("ignoreZoomSetting", true);
driver= new InternetExplorerDriver(capabilities);
driver.manage().window().maximize();
For the security settings to execute code through IE : follow the steps in this link.`
'http://www.seleniumeasy.com/selenium-tutorials/how-to-run-webdriver-in-ie-browser'
Hope this solution helps you.... :)

Disabled JavaScript on IE can cause the test to not run.
I keep reading answers to set security setting to anything as long as it's consistent, but I find it's best to set them all to Medium, as this security level won't disable JavaScript. But in any case, if one has this issue, he can choose "Custom level..." for the "Internet" option in the Security tab, and make sure that "Active Scripting" under "Scripting" is enabled.
Of course, first make sure to complete all the steps in the IEDriver docs.

Related

Link Click using selenium webdriver is giving timeout error, link is working fine on browser otherwise

I'm trying to write a piece of code using Testng in selenium, the problem is when i try to click a link, the code becomes unresponsive and gives error- Timed out receiving message from renderer
Tried driver.get("https://infostore.saiglobal.com/") instead of driver.findElement(By.linkText("Infostore")).click(); still remains unresponsive - Doesnot get directed to the webpage - https://infostore.saiglobal.com/
#Test
public void testSai() throws Exception {
driver.get("https://www.saiglobal.com/"); //open homepage
driver.findElement(By.id("CybotCookiebotDialogBodyButtonAccept")).click(); //accept cookie
driver.findElement(By.cssSelector("#sai-header > div > div.main-nav > div.store-box > div")).click(); //click on Login to open list
sleep(2);
driver.findElement(By.linkText("Infostore")).click(); //click on infostore to be redirected to https://infostore.saiglobal.com/
System.out.println(driver.getCurrentUrl());
Yes I have checked this issue and there is an workaround for this issue if you wish to have this.Try following code.
Take the href attribute value from the link element.
Delete all cookies.
driver.navigate().to(URL);
public static void main(String[] args){
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + File.separator + "\\Executables\\Chromedriver.exe");
WebDriver driver = new ChromeDriver();
WebDriverWait wait = new WebDriverWait(driver, 5);
Actions actions = new Actions(driver);
driver.get("https://www.saiglobal.com/");
driver.findElement(By.id("CybotCookiebotDialogBodyButtonAccept")).click();
WebElement element=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#class='desktop-login']")));
actions.moveToElement(element).build().perform();
WebElement element1=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#class='desktop-login']/ul/li/a[contains(text(),'Infostore')]")));
String str1=element1.getAttribute("href");
driver.manage().deleteAllCookies();
driver.navigate().to(str1);
System.out.println(driver.getCurrentUrl());
}
This seems to be an error with Selenium that the developers have been dealing with for over a year. They never really give a concrete answer as to what causes it or how to fix it.
The first port of call would be to make sure that your browser and Selenium are compatible. Try opening a different URL that you know works, and if the error persists then there is likely an error with the compatibility of your selenium and web browser. If it works, then there is something wrong with your website.
For reference, I opened your website using Python Selenium, and had no issues loading or interacting with elements. So the error is local to the software you are using.
The issue can also be caused by sleeps(no idea why), so try removing any sleeps and see if this stops the issue.

Not able to open IE browser.code and error both are in description?

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class IEdrivercode
{
public static void main(String[] args)
{
String driverpath = "path of IE Browser";
System.setProperty("webdriver.ie.driver",driverpath+"IEDriverServer.exe");
WebDriver driver=new InternetExplorerDriver();
System.out.println("Hello Google...");
driver.get("http://google.com");
driver.close();
}
}
Refer Image:
I have done all the settings from this link.
Can anyone help me on this issue?
You have to uncheck "Enable protection mode" options to run Internet Explorer Browser through webdriver.
Follow this Steps:
Tools -> Internet options -> Security
Now UNCHECK "Enable protection mode" for all the 4 zones.
Hope it will work for you.
Try this way.
Note:- IE Driver should available, and IE driver path should be correct.
This can work out of the box without the desired capability settings.
Go to internet options>>Security>>click on:'Reset all zones to default level and after that, ensure that the 'Enable protected mode' checkbox is ticked for all the four zones. Like i.e Internet , Local internet, Trusted Sites, Restricted Sites.
System.setProperty("webdriver.ie.driver", "C:\\Users\\Drivers\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://google.com");
System.out.println("Hello Google");
driver.close();

Selenium IE driver not able to find the correct page source

I have a login page which redirects to a page from where I need to extract some data from an element using selenium.
I am running the code from local eclipse using the IE driver but facing an issue as the pagesource is that of the initial web driver page after some time the IE browser does navigate to the page with some delay , but the page source remains the same and get a exception as no such element found.
Have tried to add implicity waits but did not work.
Any work around where I can induce a delay ?
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
caps.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
caps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
File file = new File("D:/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
driver = new InternetExplorerDriver(caps);
driver.get(baseUrl);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().setSize(new Dimension(600, 600));
Based on your comment (to your question) that "It does not navigate beyond the first page of the driver having title 'WebDriver'", I gather you are not able to go to login page, enter credentials and click on some button that will redirect to 2nd page.
In that case, please make you that you are using appropriate version of Internet Explorer driver. I am using 64-bit version of Internet Explorer driver as I am using 64-bit version of Internet Explorer browser and 64-bit OS on my PC. If you are using 32-bit version of Internet Explorer browser and 32-bit OS, you will need to use 32-bit version of Internet Explorer driver. How to find which version of Internet Explorer browser we are using: By checking path of it's executable file, whether it is in "Program Files" or in "Program Files (x86)" folder. How to see whether OS is 32 bit or 64 bit: Right-click on "Computer" and select "Properties".
I think following code would work:
#BeforeTest
public void setup() {
System.setProperty("webdriver.ie.driver", "C:/Dependancies/IEDriverServer.exe");
driver = new InternetExplorerDriver();
}
#Test
public void test() throws InterruptedException {
driver.get("URL_of_login_page"); // Make sure the URL begins with 'http' or 'https'.
// Enter login credentials, click on 'Submit' button so that it will redirect to 2nd page.
Thread.sleep(15000); // Assuing 15 seconds is sufficient time for the 2nd page to load.
System.out.println("The 2nd page is loaded now.");
System.out.println(driver.getTitle()); // It should print page-title of 2nd page.
String source;
source = driver.getPageSource();
System.out.println(source);
}

Selenium Webdriver - Issue while opening the specified url using driver.get()

The Url "http://localhost:8080/Login.aspx" is getting opened as "http://www.localhost.com:8080/Login.aspx" in firefox/chrome, the error page displays "The connection was reset The connection to the server was reset while the page was loading". How to avoid the www.**.com issue?
I tried searching for a solution in google, but coudln't get out of this issue.
Code Sample:
`BeforeClass
public void Setup(){
driver = new FirefoxDriver();
driver.get("http://localhost:8080/Login.aspx");
driver.manage().window().maximize();
}`
try the same thing in IDE with the open command and check if it works...if it does just export the code and use it.
Hope it works.

Selenium 2 :- selenium.isTextPresent fails assertion in IE8 while it passes in Chrome or firefox

I am trying to check for the string "Education + Add a school" for Linked profile (Under Profile -Edit Profile) in Selenium Junit 4 test case with following command:
assertTrue(selenium.isTextPresent("Education + Add a school"));
When I view the webpage source,the stirng appears in :
Education
+ Add a school
The assertTrue returns True or passes validation as expected in chrome.However in I.E 8 I get
assertionFailedError.I am using windows 7 and Selenium 2.21.0 .
I am not sure why the behaviour is different on different browser.
The code looks like :
public class test12 extends SeleneseTestCase {
#Before
public void setUp() throws Exception {selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "https://www.linkedin.com/");
selenium.start();
}
#Test
public void testTest12() throws Exception {
selenium.open("/uas/login?goback=&trk=hb_signin");
selenium.type("id=session_key-login", "xxxxx");
selenium.type("id=session_password-login", "xxxxxx");
selenium.click("id=btn-primary");
selenium.waitForPageToLoad("30000");
selenium.click("link=Edit Profile");
selenium.waitForPageToLoad("30000");
assertEquals("Improve your Profile", selenium.getText("css=a [name=\"guidedEdit\"] > span"));
assertTrue(selenium.isElementPresent("id=yui-gen8"));
//the below assertion failes in I.E 8,but it runs fine in chrome
assertTrue(selenium.isTextPresent("Education + Add a school"));
assertTrue(selenium.isElementPresent("css=#yui-gen7 > span.edit"));
assertEquals("Edit Profile | Linked", selenium.getTitle());
}
#After
public void tearDown() throws Exception {
selenium.stop();
}
}
This may be due to your IE8 settings.
When running selenium in IE you should change your Security Options under Internet Options to all have 'Enable Protected Mode' either all checked, or all unchecked (for Internet, Local, Trusted and Restricted). Another setting that can interfere is Compatibility Mode. Push F12 in an IE8 browser when running the test and look at the Browser and Document modes. If either of these say compatibility mode, you should find the Compatibility Mode settings and turn it off.
If you can't find any of these settings let me know and I can screenshot it for you (though I am running IE9) and also please say if it doesn't work, because I would be interested to know the solution then! :)
EDIT:
Solved by accessing the element and checking the text from the element. Using code:
String checkForEducation = selenium.getText("id=yui-gen10");
assertEquals("Education + Add a school", checkForEducation);