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.
Related
I want to use Selenium to navigate to a website. Selenium opens up the browser but does not navigate further to the specified website URL, but gets stuck on the "data:," url. After some time time I get the following exception:
"The HTTP request to the remote WebDriver server for URL http://localhost:58504/session timed out after 60 seconds"
Note: I did not specify the 58504 port anymore, so I guess it is the default port that Selenium use?
I am programming in C# and using the following Nuget Packages:
https://www.nuget.org/packages/Selenium.WebDriver/4.1.1
https://www.nuget.org/packages/WebDriverManager/2.13.0
Here is the code:
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;
using WebDriverManager;
using WebDriverManager.DriverConfigs.Impl;
using WebDriverManager.Helpers;
public void VisitWebsite()
{
IWebDriver driver = null;
try
{
new DriverManager().SetUpDriver(new EdgeConfig(), VersionResolveStrategy.MatchingBrowser);
EdgeOptions options = new EdgeOptions();
options.AddArgument("--no-sandbox);
options.AddArgument("--disable-infobars");
options.AddArgument("--disable-dev-shm-usage");
options.AddArgument("--disable-browser-side-navigation");
options.AddArgument("--disable-extensions");
options.AddArgument("--dns-prefetch-disable");
options.AddArgument("--disable-gpu");
options.AddArgument("--disable-software-rastersizer");
driver = new EdgeDriver(options);
}
catch (Exception ex)
{
throw ex;
}
driver.Navigate().GoToUrl("https://www.google.com");
}
Where does it go wrong? Thanks!
I found the answer. It seems the DeveloperToolsAvailability policy for the MSEdge browser had a value that "blocks" Selenium from working. You can read more about it here: https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/?tabs=c-sharp#developer-tools-availability-policy
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.
I am trying to detect the login id and password field of a website : https://mretailstore.com/login but seems selenium is not able to locate the email type box. I have checked stackoverflow but didn't get any solution to this. Someone has used iframe because of what he/she was facing the same issue but here we have not incorporated any iframe.
The error I am getting is:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: .//*[#id='identity']
The code I am using:
System.setProperty("webdriver.gecko.driver", "C:\\Users\\MI SERVICE\\Downloads\\geckodriver.exe");
FirefoxOptions capa = new FirefoxOptions();
capa.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capa);
driver.get("https://www.mretailstore.com/");
driver.findElement(By.xpath(".//*[#id='identity']")).sendKeys("abc#d.com");
driver.findElement(By.xpath(".//*[#id='password']")).sendKeys("abc123");
driver.findElement(By.id("loginbutton")).click();
driver.navigate().back();
driver.close();
It looks your xpath is correct only and this exception is happening before element rendering.So, Please add the some explicit wait after the page loading.
It is working for me with/without Explicit Wait.
Code:
driver.get("https://www.mretailstore.com/");
WebDriverWait wait=new WebDriverWait(driver,20);
wait.until(ExpectedConditions.titleIs("Login"));
driver.findElement(By.xpath(".//*[#id='identity']")).sendKeys("abc#d.com");
driver.findElement(By.xpath(".//*[#id='password']")).sendKeys("abc123");
driver.findElement(By.id("loginbutton")).click();
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);
}
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.