NoSuchSessionException: Session ID is null - selenium

org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-NLBMRCD', ip: '192.168.1.15', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_301'
Driver info: driver.version: RemoteWebDriver
i have getDriver;
public static WebDriver getDriver() {
return driver;
}
i have instantiate;
public WebDriver instantiate(String strategy) {
DriverStrategy driverStrategy = DriverStrategyImplementer.chooseStrategy(strategy);
driver = driverStrategy.setStrategy();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
return driver;
}
i have get instance;
public static DriverSingleton getInstance(String driver) {
if (instance == null) {
instance = new DriverSingleton(driver);
}
return instance;
}
config properties;
public class ConfigurationProperties {
#Value("${browser}")
private String browser;
public String getBrowser() {
return browser;
}
public void setBrowser(String browser) {
this.browser = browser;
}
}

Possibly due to older java.version: '1.8.0_301'
Ensure that JDK is upgraded to current level of JDK 8u311.

Related

When i opened Google page then every time an error was occur.Unable to create new remote session

When i trying to execute then every time an error message was occur.
Unable to create new remote session.desired capabilities = Capabilities [{marionette=true, firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions#1660f4e, browserName=firefox,moz:firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions#1660f4e, version=, platform=ANY}], required capabilities = Capabilities [{}]
Code trials:
package com.rsmpl.hometask;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class ComboValue {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "E:\\Arijit_Backup\\Utility\\Java_setup\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
FirefoxDriver fd = new FirefoxDriver(capabilities);
fd.get("http://74.50.58.66/jkhealth_test");
Thread.sleep(10000);
}
}
Are you using an admin account on your workstation? This might cause the issue.
Try specifying a path to Firefox in your capabilities:
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "E:\\Arijit_Backup\\Utility\\Java_setup\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
capabilities.setCapability("firefox_binary","pathToYourFirefoxExecutable\\Mozilla Firefox\\firefox.exe");
FirefoxDriver fd = new FirefoxDriver(capabilities);
fd.get("http://74.50.58.66/jkhealth_test");
Thread.sleep(10000);
}

Why CrossBrowser Automated Script Throws Error in Edge Browser?

Guys i Was Doing Cross Browser Automation in Chrome, FireFox and Edge . I Cant Able To Complete The Test Script in Edge Browser. I Was Getting an Error Message
"org.openqa.selenium.WebDriverException: Unknown error (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 42 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'rcktechiess-06', ip: '192.168.1.44', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_171'
Driver info: org.openqa.selenium.edge.EdgeDriver
Capabilities [{applicationCacheEnabled=true, InPrivate=false, pageLoadStrategy=normal, platform=ANY, acceptSslCerts=true, browserVersion=42.17134.1.0, platformVersion=10, locationContextEnabled=true, webStorageEnabled=true, browserName=MicrosoftEdge, takesScreenshot=true, takesElementScreenshot=true, platformName=windows}]
Session ID: B339099D-F7C6-41A7-A6E6-12D22C3D9937
I Have Attched Image For Exception. Please Check it
**Test 1 Code Using Testng**
package Crossbrowser;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class Test1 {
WebDriver driver;
#BeforeTest
#Parameters("browser")
public void setup(String browser) throws Exception
{
//Check if parameter passed from TestNG is 'firefox'
if(browser.equalsIgnoreCase("firefox"))
{
//create firefox instance
driver = new FirefoxDriver();
}
//Check if parameter passed as 'chrome'
else if(browser.equalsIgnoreCase("chrome"))
{
//set path to chromedriver.exe
System.setProperty("webdriver.chrome.driver", "F:\\New folder\\chromedriver.exe");
//create chrome instance
driver = new ChromeDriver();
}
//Check if parameter passed as 'Edge'
else if(browser.equalsIgnoreCase("Edge"))
{
//set path to IE.exe
System.setProperty("webdriver.edge.driver","F:\\New folder (2)\\MicrosoftWebDriver (1).exe");
//create Edge instance
driver = new EdgeDriver();
}
else
{
//If no browser passed throw exception
throw new Exception("Browser is not correct");
}
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
#Test
public void testParameterWithXML() throws InterruptedException
{
driver.get("http://xxxxxxxxxx/");
driver.manage().window().maximize();
driver.findElement(By.xpath("/html[1]/body[1]/div[2]/header[1]/ss-header[1]/div[1]/div[1]/div[1]/span[1]/a[1]")).click();
Thread.sleep(2000);
//Find user name
WebElement userName = driver.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/ss-auth-form[1]/md-card[1]/ss-login-form[1]/div[1]/form[1]/input[1]"));
//Fill user name
userName.sendKeys("koushick#rcktechiees.com");
//Find password
WebElement password = driver.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/ss-auth-form[1]/md-card[1]/ss-login-form[1]/div[1]/form[1]/input[2]"));
//Fill password
password.sendKeys("1234567890");
Thread.sleep(2000);
driver.findElement(By.xpath("//form[#name='myForm']//ss-submit-button[#label='Log In']//input[#class='submit']")).click();
Thread.sleep(1000);
Test2 obj = PageFactory.initElements(driver, Test2.class);
Thread.sleep(2000);
try
{
Actions a1 = new Actions(driver);
a1.moveToElement(obj.getE1()).click(obj.getE2()).build().perform();
}
catch(Exception e)
{
System.out.println("Can't Click on The Elemnet");
}
Thread.sleep(2000);
try
{
Actions a2 = new Actions(driver);
a2.moveToElement(obj.getE3()).click(obj.getE3()).build().perform();
}
catch(Exception e)
{
System.out.println("Can't Click");
}
Thread.sleep(2000);
try
{
Actions a3 = new Actions(driver);
a3.moveToElement(obj.getE4()).click(obj.getE5()).build().perform();
}
catch(Exception e)
{
System.out.println("Can't Click on The Elemnet");
}
Thread.sleep(2000);
obj.getE6().sendKeys("ss#gmail.com");
Thread.sleep(2000);
obj.getE7().click();
Thread.sleep(2000);
obj.getE8().click();
Thread.sleep(2000);
driver.navigate().to("http://XXXXXXXXXXXX/");
Thread.sleep(2000);
driver.findElement(By.xpath("//a[#classname='nav-link men']")).click();
Thread.sleep(2000);
}
#AfterTest
public void MatchitnowWithXML() throws InterruptedException
{
Test2 obj1 = PageFactory.initElements(driver, Test2.class);
Actions a4 = new Actions(driver);
a4.moveToElement(obj1.getE9()).click(obj1.getE9()).build().perform();
Thread.sleep(2000);
obj1.getE10().click();
Thread.sleep(2000);
obj1.getE11().click();
Thread.sleep(2000);
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollTop = arguments[1];",driver.findElement(By.id("sylnk-it")), 500);
Thread.sleep(2000);
obj1.getE12().click();
Thread.sleep(2000);
Actions a5 = new Actions(driver);
a5.moveToElement(obj1.getE13()).click(obj1.getE13()).build().perform();
Thread.sleep(2000);
try
{
driver.findElement(By.xpath("//button[#class='cal-sly']")).click();
}
catch (Exception e)
{
System.out.println("Not Visible To Click");
}
Thread.sleep(2000);
driver.navigate().back();
Thread.sleep(2000);
driver.navigate().back();
Thread.sleep(2000);
try
{
Actions a6 = new Actions(driver);
a6.moveToElement(obj1.getE14()).click(obj1.getE15()).build().perform();
}
catch(Exception e)
{
System.out.println("Can't Move To The Element and Click");
}
Thread.sleep(2000);
try
{
Actions a7 = new Actions(driver);
a7.moveToElement(obj1.getE16()).click(obj1.getE17()).build().perform();
}
catch(Exception e)
{
System.out.println("Can't Click on the Element !");
}
Thread.sleep(3000);
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("window.scrollBy(0,250)");
Thread.sleep(1000);
try
{
Actions a8 = new Actions(driver);
a8.moveToElement(obj1.getE18()).click(obj1.getE19()).build().perform();
}
catch(Exception e)
{
System.out.println("Can't Move To The Element and Click");
}
Thread.sleep(2000);
try
{
Actions a9 = new Actions(driver);
a9.moveToElement(obj1.getE20()).click().build().perform();
}
catch(Exception e)
{
System.out.println("Can't Click");
}
Thread.sleep(2000);
try
{
driver.findElement(By.xpath("/html[1]/body[1]/div[2]/ss-app[1]/ss-search-page[1]/div[2]/ss-search-filters[1]/ss-slide-filter[1]/ss-search-filter[1]/div[1]/div[2]/span[1]")).click();
}
catch(Exception e)
{
System.out.println("Can't Click");
}
}
}
Down am Attaching Page ObjectModel Framework Code
**Test2 Code Using POM Framework Using GET Method**
package Crossbrowser;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
public class Test2 {
public WebElement getE1() {
return e1;
}
public WebElement getE2() {
return e2;
}
public WebElement getE3() {
return e3;
}
public WebElement getE4() {
return e4;
}
public WebElement getE5() {
return e5;
}
public WebElement getE6() {
return e6;
}
public WebElement getE7() {
return e7;
}
public WebElement getE8() {
return e8;
}
public WebElement getE9() {
return e9;
}
public WebElement getE10() {
return e10;
}
public WebElement getE11() {
return e11;
}
public WebElement getE12() {
return e12;
}
public WebElement getE13() {
return e13;
}
public WebElement getE14() {
return e14;
}
public WebElement getE15() {
return e15;
}
public WebElement getE16() {
return e16;
}
public WebElement getE17() {
return e17;
}
public WebElement getE18() {
return e18;
}
public WebElement getE19() {
return e19;
}
public WebElement getE20() {
return e20;
}
#FindBy(xpath="/html[1]/body[1]/div[2]/header[1]/ss-header[1]/div[1]/div[1]/ss-user-dropdown[1]/div[1]/ss-svg-icon[1]/span[1]/i[1]")
private WebElement e1;
#FindBy(xpath="/html[1]/body[1]/div[2]/header[1]/ss-header[1]/div[1]/div[1]/ss-user-dropdown[1]/div[1]/div[1]/a[9]")
private WebElement e2;
#FindBy(xpath="//button[#id='ranomizeButton']")
private WebElement e3;
#FindBy(xpath="/html/body/div[2]/header/ss-header/div/div[2]/ss-user-dropdown/div")
private WebElement e4;
#FindBy(xpath="/html/body/div[2]/header/ss-header/div/div[2]/ss-user-dropdown/div/div/a[3]")
private WebElement e5;
#FindBy(xpath="/html[1]/body[1]/div[2]/div[4]/div[2]/div[1]/div[2]/div[2]/div[1]/div[1]/input[1]")
private WebElement e6;
#FindBy(xpath="/html[1]/body[1]/div[2]/div[4]/div[2]/div[1]/div[2]/div[2]/div[1]/button[1]")
private WebElement e7;
#FindBy(xpath="/html[1]/body[1]/div[2]/div[5]/div[1]/div[1]/div[2]/div[1]/div[1]/button[1]")
private WebElement e8;
#FindBy(xpath="/html/body/div[2]/ss-app/ss-search-page/div[4]/div[2]/ss-products-list/div[2]/span[3]/ss-product-cell/div/div[4]/span")
private WebElement e9;
#FindBy(xpath="/html/body/div[2]/ss-app/div[6]/div/ss-auth-form/md-card/div[1]/span[1]/div/div[2]/label/span")
private WebElement e10;
#FindBy(id="C5")
private WebElement e11;
#FindBy(id="slynk_save")
private WebElement e12;
#FindBy(xpath="/html[1]/body[1]/div[2]/ss-app[1]/ss-header[1]/div[1]/div[1]/span[2]")
private WebElement e13;
#FindBy(xpath="/html[1]/body[1]/div[2]/ss-app[1]/ss-search-page[1]/div[4]/div[2]/ss-products-list[1]/div[2]/span[1]/ss-product-cell[1]/div[1]/div[5]")
private WebElement e14;
#FindBy(xpath="/html[1]/body[1]/div[2]/ss-app[1]/ss-search-page[1]/div[4]/div[2]/ss-products-list[1]/div[2]/span[1]/ss-product-cell[1]/div[1]/div[5]/a[2]/span[1]/i[1]")
private WebElement e15;
#FindBy(xpath="//ss-product-cell[#id='110743~Dresslily~womens-tops~womens-tops']//div[#class='product-cell-container extended-cell']//div[#class='bottom-icons']")
private WebElement e16;
#FindBy(xpath="//span[#id='~110743~Stylish Lace Embellished Short Sleeve Scoop Neck Womens TShirt~Dresslily~Dresslily~Dresslily~womens-tops~womens-tops~~undefined~$4.99~$9.67~~^^womens-tops^womens-clothes^women ']//i[#class='icon-12']")
private WebElement e17;
#FindBy(xpath="//ss-product-cell[#id='304028~GuessFactory~shorts~shorts']//div[#class='product-cell-container extended-cell']//div[#class='bottom-icons']")
private WebElement e18;
#FindBy(xpath="//span[#id='~304028~Shelby Denim Shorts~GuessFactory~Guess Factory~Guess Factory~shorts~shorts~~undefined~~$44.99~~^^shorts^womens-clothes^women ']//i[#class='icon-12']")
private WebElement e19;
#FindBy(xpath="/html[1]/body[1]/div[2]/ss-app[1]/ss-search-page[1]/div[2]/ss-search-filters[1]/ss-slide-filter[1]/ss-search-filter[1]/span[1]")
private WebElement e20;
PS: While Executing The Test Script are Sucessfully Passing in Chrome and FireFox. But Failing in Edge Only at The Middle of Automation Some Kind of Stack Error. Down Am Also Attching The XML Please Give Me a Solution To Find a BetterWay.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" >
<test name="FirefoxTest">
<parameter name="browser" value="firefox">
<classes>
<class name="Crossbrowser.Test1"/>
</classes>
</parameter>
</test> <!-- Test -->
<test name="chromeTest">
<parameter name="browser" value="chrome">
<classes>
<class name="Crossbrowser.Test1"/>
</classes>
</parameter>
</test> <!-- Test -->
<test name="EdgeTest">
<parameter name="browser" value="Edge">
<classes>
<class name="Crossbrowser.Test1"/>
</classes>
</parameter>
</test> <!-- Test -->
</suite> <!-- Suite -->

Selenium "no such session" error on TestNG testing.xml

I am trying to run a simple test with crossbrowsers using testing.xml of TestNG. Script runs fine on the first run which is Chrome. But gives "no such session" error on the firefox test beginning.
I simplified the codes to make it easy to read. I hope it helps.
Here's my TestNG testing.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="DefaultSuite" thread-count="1" parallel="tests">
<test name="ChromeTest">
<parameter name="browser" value="Chrome" />
<classes>
<class name="loginTest">
</class>
</classes>
</test>
<test name="FirefoxTest">
<parameter name="browser" value="Firefox" />
<classes>
<class name="loginTest">
</class>
</classes>
</test>
</suite>
And here's my code
public class loginTest {
private static WebDriver driver;
#BeforeTest
#Parameters("browser")
public void testSetup(String browser) throws Exception {
//Check if parameter passed from TestNG is 'firefox'
if(browser.equalsIgnoreCase("firefox")){
driver = webBrowsers.browserAl("Firefox");
}
//Check if parameter passed as 'chrome'
else if(browser.equalsIgnoreCase("chrome")){
driver = webBrowsers.browserAl("Chrome");
}
else{
//If no browser passed throw exception
throw new Exception("Browser is not correct");
}
}
#Test(priority=0)
public void LoginTest(){
driver.get("http://www.hurriyet.com.tr/");
}
#AfterTest
public void kapat() {
webBrowsers.closeDriver();
}
}
and finally my webBrowsers.class
public class webBrowsers {
private static WebDriver driver = null;
private static String browserName;
public static WebDriver browserAl(String browserName) {
if (browserName.equals("Firefox")) {
if (driver == null) {
System.setProperty("webdriver.gecko.driver","./drivers/geckodriver.exe");
driver = new FirefoxDriver();
}
} else if (browserName.equals("Edge")) {
if (driver == null) {
System.setProperty("webdriver.edge.driver", "./drivers/MicrosoftWebDriver.exe");
driver = new EdgeDriver();
}
} else if (browserName.equals("Chrome")) {
if (driver == null) {
System.setProperty("webdriver.chrome.driver","./drivers/chromedriver.exe");
driver = new ChromeDriver();
}
}
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
return driver;
}
public static void closeDriver() {
driver.close();
}
}
The problem is in your class webBrowsers. You are working with a static webdriver instance. So for the first <test> execution the driver instance will not be null and it would get instantiated properly. But when you execute the second <test> tag, the condition driver == null would be false, and you end up getting reference to the webdriver object that was created for the previous <test> tag. To make matters worse, you have a #AfterTest method which cleans up the driver instance as well. So you are now essentially working with a valid webdriver instance but for which the opened session has already been cleaned up.
End result : Your error.
Here's a cleaned up version of your code that should get past this problem.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
public class WebBrowsers {
public static WebDriver browserAl(String browserName) {
WebDriver driver = null;
if (browserName.equals("Firefox")) {
System.setProperty("webdriver.gecko.driver", "./drivers/geckodriver.exe");
driver = new FirefoxDriver();
} else if (browserName.equals("Edge")) {
System.setProperty("webdriver.edge.driver", "./drivers/MicrosoftWebDriver.exe");
driver = new EdgeDriver();
} else if (browserName.equals("Chrome")) {
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
driver = new ChromeDriver();
}
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
return driver;
}
public static void closeDriver(WebDriver driver) {
if (driver != null) {
driver.quit();
}
}
}
Here's how your test class would look like
import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class LoginTest {
private WebDriver driver;
#BeforeTest
#Parameters("browser")
public void testSetup(String browser) throws Exception {
//Check if parameter passed from TestNG is 'firefox'
if (browser.equalsIgnoreCase("firefox")) {
driver = WebBrowsers.browserAl("Firefox");
}
//Check if parameter passed as 'chrome'
else if (browser.equalsIgnoreCase("chrome")) {
driver = WebBrowsers.browserAl("Chrome");
} else {
//If no browser passed throw exception
throw new Exception("Browser is not correct");
}
}
#Test
public void loginTest() {
driver.get("http://www.hurriyet.com.tr/");
}
#AfterTest
public void kapat() {
WebBrowsers.closeDriver(driver);
}
}

Why is Gecko Driver (v0.17.0 - x64bit) not opening Browser?

Why is Gecko Driver (v0.17.0 - x64bit) not opening Browser?
Base Page / Method:
public BasePage loadUrl(String url) throws Exception {
driver.get(url);
return new BasePage(driver);
}
Cucumber Step:
#Given("^User navigates to the \"([^\"]*)\" website$")
public void user_navigates_to_the_website(String url) throws Throwable {
BasePage basePage = new BasePage(driver);
basePage.loadUrl(url);
}
Driver Factory:
public WebDriver getDriver() {
try {
if(driver == null){
System.setProperty("webdriver.gecko.driver", Constant.GECKO_DRIVER_DIRECTORY);
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
basePage = PageFactory.initElements(driver, BasePage.class);
loginPage = PageFactory.initElements(driver, LoginPage.class);
}
} catch (Exception e) {
}
return driver;
}
NEW CODE - Driver Factory: uses if statements to point to exe files for each browser type:
public WebDriver getDriver() {
try {
ReadConfigFile file = new ReadConfigFile();
if (driver == null) {
if("chrome".equalsIgnoreCase(file.getBrowser())){
System.setProperty("webdriver.chrome.driver", Constant.CHROME_DRIVER_DIRECTORY);
driver = new ChromeDriver();
}
if("firefox".equalsIgnoreCase(file.getBrowser())){
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
System.setProperty("webdriver.gecko.driver", Constant.GECKO_DRIVER_DIRECTORY);
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);
}
if("ie".equalsIgnoreCase(file.getBrowser())){
System.setProperty("webdriver.ie.driver", Constant.IE_DRIVER_DIRECTORY);
driver = new InternetExplorerDriver();
}
}
}
fixed upgrading to Selenium version: 3.4.0

UnreachableBrowserException in Selenium webdriver scripts

org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:09:54'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_29'
Driver info: driver.version: RemoteWebDriver
This is the error message which gets displayed when I am trying to run my scripts?
Scenario :My one java file has login function and second has creation of a new Account after login
Kindly advise.
Login.java:
public class LoginPage
{
public static WebDriver driver;
public static final LoginPage login = new LoginPage(new FirefoxDriver());
public LoginPage(WebDriver driver)
{
LoginPage.driver = driver;
}
public static void loginAs(String username, String password)
{
DesiredCapabilities ieCapabilities = DesiredCapabilities.firefox();
ieCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
Proxy proxy = new Proxy();
proxy.setProxyAutoconfigUrl("http://www.config.barclays.co.uk:9000/");
driver.close();
ieCapabilities. setCapability(CapabilityType.PROXY, proxy);
FirefoxDriver driver = new FirefoxDriver(ieCapabilities);
driver.get("https://login.salesforce.com");
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
//Login to Salesforce Application
try
{
driver.findElement(By.id("username")).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.id("Login")).click();
driver.manage().timeouts().implicitlyWait(75, TimeUnit.SECONDS);
}
catch(Exception e1)
{
System.out.println(e1 +"Your login attempt has failed. The username or password may be incorrect, or your location or login time may be restricted. Please contact the administrator at your company for help.");
}
}
public static void main(String[] args)
{
login.loginAs("me#example.com", "Pa$$word");
}
}
Second File where I am trying to click on Opportunity tab of my Sales force application :
CreatOpportunity.java these lines are under my main argument
LoginPage.login.loginAs("username", "password");
LoginPage.login.driver.findElement(By.id("Opportunity_Tab")).click();
Running my second file allows me to launch my application but does not detect the click on the Opprtunity tab and throws me the error mentioned above
just give a try with by putting below line after login.
driver.switchTo.defaultContent();
try with below code.
public class LoginPage {
public static WebDriver driver;
public LoginPage()
{
DesiredCapabilities ieCapabilities = DesiredCapabilities.firefox();
ieCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
Proxy proxy = new Proxy();
proxy.setProxyAutoconfigUrl("http://www.config.barclays.co.uk:9000/");
ieCapabilities. setCapability(CapabilityType.PROXY, proxy);
LoginPage.driver = new FirefoxDriver(ieCapabilities);
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
}
public static void loginAs(String username, String password) {
driver.get("https://login.salesforce.com");
//Login to Salesforce Application
try
{
driver.findElement(By.id("username")).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.id("Login")).click();
driver.manage().timeouts().implicitlyWait(75, TimeUnit.SECONDS);
}
catch(Exception e1) {
System.out.println(e1 +"Your login attempt has failed. The username or password may be incorrect, or your location or login time may be restricted. Please contact the administrator at your company for help.");
}
}
public static void main(String[] args)
{
LoginPage login = new LoginPage();
login.loginAs("me#example.com", "Pa$$word");
FileTwo.clickOpportunity(driver);
}
}
FileTwo
public class FileTwo
{
public static void clickOpportunity(WebDriver driver)
throws Exception
{
driver.findElement(By.id("Opportunity_Tab")).click();
}
}
Selenium throws this error if you call quit() method & try to launch browser again. Workaround is use close() method instead of quit()