Selenium IE driver not able to find the correct page source - selenium

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);
}

Related

How to perform automation in edge browser open using desktop application?

I have a Web application to automate using selenium and Java.
Application supports IE Browser on windows10 and for windows11 we have created an .lnk file to open same application in Edge browser because IE is no longer. And we have some videos to be streamed in application for which media player to be installed and more.
Scenario :
I have to open ABC.lnk application from desktop
Once clicked on ABC.lnk application, our application will open in Edge browser.
for step 1 : using below code to open ABC.lnk application
public static void openWindowApplication() {
String command = "C:\\Users\\Kasper\\Desktop\\ABC.lnk";
try {
Runtime.getRuntime().exec("cmd /c " + command);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Step 2 :
Edge driver initialization Code :
System.setProperty("webdriver.edge.driver", FileReaderManager.getInstance().getConfigReader().getDriverPath() + "/msedgedriver.exe");
//Creating an object of EdgeDriver
driver = new EdgeDriver();
driver.manage().window().maximize();
//Deleting all the cookies
driver.manage().deleteAllCookies();
//Specifiying pageLoadTimeout and Implicit wait
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
I have used above code to achieve above scenarios. But 2 edge browsers are getting open and nothing is happening because of above code snippet and Step 1 is required to open ABC.lnk and application opens in edge browser on click on it.
And I have to perform automation on open browser through ABC.lnk click.
How can I perform automation in same edge browser open in step 1.
Thanks in advance.

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.

Internet Explorer is not closing via selenium script with every solution

I am Not able to close the Internet Explorer via selenium script, I tried every Solution to Kill the IEDriver task and Iexplorer.exe.
I also Tried solution: Internet Explorer 11 does not close after Selenium Test 2 but it still not working for me.
I am Using below,
Selenium 3.4,
IE: 11.1358.14393.0,
InternetExplorerServerDriver: 3.4.0
Below is my code.
import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Tc03_IEDriver_First_use {
public static void main(String[] args) throws Exception {
//Set IEDriver Properties
System.setProperty("webdriver.ie.driver", "D:\\Rohit Bhatkar\\Selenium Jars\\IEDriverServer_x64_3.4.0\\IEDriverServer.exe");
//Set desired Capabilities of IE. these statements removes an zoomsetting error.
//You Can set Zoom mannually as, Go To View Menu on IE > Click On Zoom > Select 100%
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability("ignoreZoomSetting", true);
//Create IEDriver obj, Open Browser, Open URL, Close the Browser
WebDriver obj1= new InternetExplorerDriver(caps);
obj1.manage().window().maximize();
obj1.get("https://www.google.com");
obj1.quit(); //IE not Closing. Steel need to do some work to close the browser
}
}
I would try to first obj1.close() to close the browser window. Then I would use obj1.quit() to quit the webdriver which would close it's terminal window in Windows.
Your code seems to work fine. I tested it and the IE browser closed at the end.
Try obj1.close(); instead of obj1.quit();
Here is the Answer to your Question:
Try these settings for IE 11:
Note: You have to set Zoom Level to 100% for IE to work properly.
System.setProperty("webdriver.ie.driver", "C:\\Utility\\BrowserDrivers\\IEDriverServer.exe");
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability("platform", "WIN8");
cap.setCapability("version", "11");
cap.setCapability("browserName", "internet explorer");
cap.setCapability("ignoreProtectedModeSettings",1);
cap.setCapability("nativeEvents","false");
cap.setCapability("ignoreZoomSetting", true);
cap.setCapability("requireWindowFocus","true");
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
WebDriver driver = new InternetExplorerDriver(cap);
driver.manage().window().maximize();
driver.get("https://google.co.in");
System.out.println(driver.getTitle());
driver.quit();
Let me know if this Answers your Question.

Unable to launch IE browser in selenium webdriver

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.

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.