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

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.

Related

Selenium: Unable to locate email type box, not within any iframe

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

IE browser gets shrunk during execution

I am facing an weird issue. I have a selenium suite to execute on multiple browsers. It works fine of chrome and Firefox. But in case of IE, the web page under test gets shrunk (web page resize) making elements hidden. Hence facing NoSuchElementException.
I have already tried executing on full screen. No help.
Please help in solving this issue.
Thanks,
Praveen
Don't know the exact reason for that, however, suggested workaround would be to implement pre-execution method for your test which would take care of all your browser different configurations. For example, if you are using Java with Selenium and JUnit5, it might be:
#BeforeEach
void beforeTestExecution() {
DesiredCapabilities desiredCapabilities = DesiredCapabilities.internetExplorer();
desiredCapabilities.setCapability(
CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
driver = new InternetExplorerDriver(desiredCapabilities);
// Navigate to URL
driver.get("http://www.yoursite.com");
// Maximize your website window before test.
driver.manage().window().maximize();
}
Or:
#BeforeEach
void configBrowser() {
DesiredCapabilities desiredCapabilities = DesiredCapabilities.internetExplorer();
desiredCapabilities.setCapability(
CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
driver = new InternetExplorerDriver(desiredCapabilities);
// Start Internet Explorer maximized.
driver.manage().window().maximize();
}

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.

How to stop page load in Selenium Webdriver

I have logged into an account on one of the websites. After login, a click on a button presents that page, but the page keeps on loading without displaying the next page.
What I wanted is, if the page keeps on loading without giving any response for some time, I need to stop the execution of the script.
I have tried by using the below code, but it didn't work
driver.manage().timeouts().pageLoadTimeout(500, TimeUnit.MILLISECONDS);
If you are using firefox, use firefox profile with selenium and set network.http.connection-timeout to seconds (for ex I am setting it to 10 secs) -
In Java,
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.http.connection-timeout", 10);
For stopping the page-load you can use this
public void stopPageLoading() {
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("return window.stop");
}

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.