Getting 500 error page on logout by Selenium Webdriver script - selenium

Updated with code
driver.get("https://stage.ab.org/");
System.out.println(driver.getTitle());
System.out.println(driver.getPageSource());
driver.findElement(By.id("txt-username")).sendKeys("Username");
driver.findElement(By.id("pwd-password")).sendKeys("Passw0rd");
driver.findElement(By.id("login-widget-submit")).click();
Thread.sleep(2000);
driver.findElement(By.cssSelector(".username-link-container")).click();
Thread.sleep(8000);
WebDriverWait wait = new WebDriverWait(driver, 9);
WebElement link = wait.until(ExpectedConditions.elementToBeClickable(By.id("alinkSignOut")));
link.click();
I do not get any errors in Eclipse.
When the Webdriver script runs (logging out a user) it gives 500 Error page. When I do it manually, I am able to it successfully. What is going on with Selenium?

Some issues with VPN, working fine now

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.

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

Selenium NoSuchElementException with InternetExplorerDriver

I'm doing some R&D with Selenium and I've found an inconsistancy I can't explain between the InternetExplorerDriver and the ChromeDriver.
I run this code:
var driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://www.google.com");
var query = driver.FindElement(By.Name("q"));
query.SendKeys("Hello World!");
query.Submit();
Everything works fine, my browser navigates to google and searches for "Hello World!".
But when I try exactly the same code with the InternetExplorerDriver
var driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://www.google.com");
var query = driver.FindElement(By.Name("q"));
query.SendKeys("Hello World!");
query.Submit();
I get an error on the FindElement line.
An exception of type 'OpenQA.Selenium.NoSuchWindowException' occurred
in WebDriver.dll but was not handled in user code
Additional information: Unable to find element on closed window
I have IE 11.0.9600.17905 installed.
Am I missing a step with IE?
Check out the required configuration section on the IEDriver wiki. I would hazard a guess and say your problem is "you must set the Protected Mode settings for each zone to be the same value".

Script runs fine in debug mode but not runs in run mode in IE Browser

i have tried following code both in Firefox and IE.
Firefox it is working fine but in IE it is not working . Im using IEv11 ,selenium v2.45 and also i tried with v2.46 and 2.44 .IE Driver Server v2.46. Please help me
public class IEBrowser {
WebDriver driver;
#Test
public void url(){
System.setProperty("webdriver.ie.driver", "E:\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
driver.get("http://www.toolsqa.com/automation-practice-form/");
driver.findElement(By.name("firstname")).sendKeys("hi");
}
}
Use this code before finding the elements:
try {
Thread.sleep(10000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
This is applicable to any appium project. *Works in Android Appium too.
It's working fine in my System for all browsers.This may be due to internet speed as well.Any how add a WebDriverWait and see
driver.get("http://www.toolsqa.com/automation-practice-form/");
WebDriverWait wait = new WebDriverWait(driver, 40);//Unit in Seconds
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("firstname"))).sendKeys("hi");

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