org.openqa.selenium.WebDriverException: chrome not reachable using Selenium and ChromeDriver - java

I created a test class using TestNG and in this class I defined 5 test methods. When I run the test, the TestNG console shows that 3 scenarios of the total of 5 have been executed (see the image below).
The registroNovo and tabulacaoTratamento methods are not executed.
When I close the browser (Chrome) the TestNG console displays the following error screen that follows below.
Eclipse console displays the following error message:
org.openqa.selenium.WebDriverException: chrome not reachable
(Session info: chrome=67.0.3396.87)
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.8.0', revision: '924c4067df', time: '2017-11-30T11:36:59.109Z'
System info: host: 'RJO-BCC-C2A-H21', ip: '10.5.79.38', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.40.565498 (ea082db3280dd6..., userDataDir: C:\Users\lsnpere\AppData\Lo...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 67.0.3396.87, webStorageEnabled: true}
Session ID: 32d0291ab5ecaa1141f9997771edcd95
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:658)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.alert(RemoteWebDriver.java:987)
at org.openqa.selenium.support.ui.ExpectedConditions$28.apply(ExpectedConditions.java:808)
at org.openqa.selenium.support.ui.ExpectedConditions$28.apply(ExpectedConditions.java:804)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
at page.RegistroNovo.registroNovo(RegistroNovo.java:25)
at test.ValidarFaturamentoRoamingTest.registroNovo(ValidarFaturamentoRoamingTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Has anyone ever seen this kind of error?
Basically I created 4 classes:
The BaseTest class which has all methods that are common to all test classes:
public class BaseTest {
public static WebDriver driver;
public static WebDriverWait wait;
#BeforeClass
public static void setup() {
System.setProperty("webdriver.chrome.driver", "e:\\Selenium\\chromedriver.exe");
driver = new ChromeDriver();
wait = new WebDriverWait(driver, 15);
driver.manage().window().maximize();
}
#AfterClass
public static void tearDown() throws InterruptedException {
Thread.sleep(5000);
driver.findElement(By.id("mn_sair"));
driver.quit();
}}
The test class ValidarFaturamentoRoamingTest which extends the class BaseTest:
public class ValidarFaturamentoRoamingTest extends BaseTest {
#Test(priority=0)
public void acessarBkoMais() {
HomePage homepage = new HomePage(driver, wait);
homepage.abrirBkoMais();
}
#Test(priority=1)
public void logarBkoMais() {
LoginPage logar = new LoginPage(driver, wait);
logar.loginBkoMais("000000", "000000");
}
#Test(priority=2)
public void logarEstrategia() {
LogarEstrategiaPage logarEstrategia = new LogarEstrategiaPage(driver, wait);
logarEstrategia.logarEstrategia();
}
#Test(priority=3)
public void registroNovo() {
RegistroNovo registroNovo = new RegistroNovo(driver, wait);
registroNovo.registroNovo();
}
#Test(priority=4)
public void tabulacaoTratamento() {
TratOsFatRoamPage rt = new TratOsFatRoamPage(driver, wait);
rt.TratOsFatRoam();
}}
The class TratOsFatRoamPage which extends the class BasePage.
public class TratOsFatRoamPage extends BasePage {
public TratOsFatRoamPage(WebDriver driver, WebDriverWait wait) {
super(driver, wait);
}
String idMotivo = "cboMotivo";
String idSubMotivo = "cboSubMotivo";
String idStatus = "cboStatus";
String qtdNumerosFaturas = "txtQtdFaturas";
String qtdNumerosCotas = "txtQtdContas";
String idObservacao = "txtObservacao";
String idSalvar = "btnSalvar";
public void TratOsFatRoam() {
writeText(By.id(qtdNumerosFaturas),"Teste 2018");
writeText(By.id(qtdNumerosCotas), "2018-2");
}}
And the class BasePage which has all the methods that are common classes:
public class BasePage {
public WebDriver driver;
public WebDriverWait wait;
public BasePage(WebDriver driver, WebDriverWait wait) {
this.driver = driver;
this.wait = wait;
}
public void click(By elementLocation) {
driver.findElement(elementLocation).click();
}
public void writeText(By elementLocation, String text) {
driver.findElement(elementLocation).sendKeys(text);
}
public String readText(By elementLocation) {
return driver.findElement(elementLocation).getText();
}
public void selectText(By elementLocation, String value) {
Select atividade = new Select(driver.findElement(elementLocation));
atividade.selectByValue(value);
}}

This error message...
org.openqa.selenium.WebDriverException: chrome not reachable
...implies that the ChromeDriver was unable to communicate with the WebBrowser i.e. Chrome Browsing session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.40
You are using chrome=67.0
Your Selenium Client version is 3.8.0 of 2017-11-30T11:36:59.109Z which is almost six months older.
Your JDK version is 1.8.0_131 which is pretty ancient.
So there is a clear mismatch between the JDK v8u131 , Selenium Client v3.8.0 , ChromeDriver v2.40 and Chrome Browser v67.0

org.openqa.selenium.WebDriverException: chrome not reachable
This means that for some reason there is no communication happening between driver and chrome instance; in your case that reason is you are closing it manually after 3 Tests are run.
and your TestNG console displays the error screen because last 2 test cases weren't run due to closing of browser.
So here your real issue is what is taking second last test to take time?
For that post some code.

Related

Why doesn't Selenium #FindBy work with name, xpath, css

I have a Java program using Selenium and would like to use #FindBy(), but I can't solve the problem. My program is composed of several lines. I would like to share tasks between classes. And for that, I started with identity verification. I created this class which includes login and password.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
public class LoginPageNew {
WebDriver webDriver;
public LoginPageNew(WebDriver driver) {
this.webDriver = driver;
}
#FindBy(css = "[name='username']")
#CacheLookup
WebElement username;
#FindBy(how = How.NAME, using = "password")
#CacheLookup
WebElement password;
#FindBy(how = How.XPATH, using = "//button[normalize-space()='Login']")
#CacheLookup
WebElement submit_btn;
public void loginPage() {
username.sendKeys("Admin");
password.sendKeys("admin123");
submit_btn.click();
}
}
And I created this class
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class BrowserFactory {
static WebDriver driver;
public static WebDriver startBrowser(String browserName, String url) {
if (browserName.equals("chrome")) {
driver = new ChromeDriver();
}
driver.manage().window().maximize();
driver.get(url);
return driver;
}
}
And finally this test class
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.Test;
public class VerifyLoginPage {
#Test
public void checkValidUser() {
WebDriver webDriver = BrowserFactory.startBrowser("chrome", "http://opensource-demo.orangehrmlive.com/");
LoginPageNew pageNew = PageFactory.initElements(webDriver, LoginPageNew.class);
pageNew.loginPage();
}
}
For me, I would like to work with the site "https://opensource-demo.orangehrmlive.com/" with login and password "Admin" and "admin123" with this architecture to do the test.
And I used
#FindBy(name="username"), #FindBy(css = "[name='username']"),
#Find By(xpath = "//input[#placeholder='Username']")
#Find By(xpath = "(//input[#placeholder='Username'])[1]")
#Find By(how = How. NAME, using = "username")...
But there is no solution, always the same error.
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"[name='username']"}
(Session info: chrome=109.0.5414.76)
For documentation on this error, please visit: https://selenium.dev/exceptions/#no_such_element
Build info: version: '4.7.2', revision: '4d4020c3b7'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.16'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [f3cd14b65540143dd77567fdbdd70945, findElement {using=css selector, value=
[name='username']}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 109.0.5414.76,
chrome: {chromedriverVersion: 109.0.5414.74 (e7c5703604da..., userDataDir:
C:\Users\hp\AppData\Local\T...}, goog:chromeOptions: {debuggerAddress: localhost:64620},
networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: WINDOWS, proxy:
Proxy(), se:cdp: ws://localhost:64620/devtoo..., se:cdpVersion: 109.0.5414.76, setWindowRect:
true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script:
30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true,
webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
I will add this code
webDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
thank you BMW83

FAILED CONFIGURATION: #BeforeMethod setUp - Selenium Java TestNG

I am trying to execute Selenium Java Project with TestNG but I am getting the Configurations Problems related to TestNG annotations. I am using Page object model design pattern. The chromedriver gets executed successfully for each testcase and it lands on login page but after that it crashes and gives error about Failed Configurations #BeforeMethod.
I am sharing the whole code and console errors. Any Solution for this folks! Been stuck here for the long time.
Page Classes.
Base Page:
package Pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
public class BasePage{
public WebDriver driver;
public WebDriverWait wait;
public BasePage(WebDriver driver, WebDriverWait wait) {
this.driver = driver;
this.wait = wait;
}
//Generic Methods
public void click(By elementlocation) {
driver.findElement(elementlocation).click();
}
public void writeText(By elementlocation, String text) {
driver.findElement(elementlocation).sendKeys(text);
}
public String readText(By elementlocation) {
return driver.findElement(elementlocation).getText();
}
public void waitVisibility(By elementlocation) {
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(elementlocation));
}
public void waitElementToBeClickable(By elementlocation ) {
wait.until(ExpectedConditions.elementToBeClickable(elementlocation));
}
public void assertEquals (By elementlocation, String expectedText) {
waitVisibility(elementlocation);
Assert.assertEquals(readText(elementlocation), expectedText);
}
}
Login Page with Methods:
package Pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
public class LoginPage extends BasePage{
public LoginPage(WebDriver driver, WebDriverWait wait) {
super(driver, wait);
}
By email = By.xpath("//input[#data-placeholder='Enter your username']");
By pwd = By.xpath("//input[#data-placeholder='Enter your Password']");
By LoginBtn = By.xpath("//button//span[text()='Login']");
By emptyLoginVerification = By.xpath("//span[contains(text(),'Both Password and user name are required.')]");
By emptyPasswordVerification = By.xpath("//span[contains(text(),'Both Password and user name are required.')]");
By emptyUserNameVerification = By.xpath("//span[contains(text(),'Both Password and user name are required.')]");
//methods
public LoginPage LoginToAMS(String username, String password) {
writeText(email, username);
writeText(pwd, password);
click(LoginBtn);
return this;
}
public LoginPage EmptyLoginVerification (String expectedText) {
assertEquals(emptyLoginVerification, expectedText);
return this;
}
public LoginPage EmptyPasswordVerification (String expectedText) {
assertEquals(emptyPasswordVerification, expectedText);
return this;
}
public LoginPage EmptyUserNameVerification (String expectedText) {
assertEquals(emptyUserNameVerification, expectedText);
return this;
}
}
Below are the TestClasses Now.
BaseTest:
package tests;
import java.time.Duration;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
public class BaseTest {
public WebDriver driver;
public WebDriverWait wait;
#BeforeMethod
public void setup() {
System.setProperty("WebDriver.chrome.driver", "C:\\eclipse\\eclipse-workspace\\ams\\chromedriver.exe");
driver = new ChromeDriver();
wait = new WebDriverWait(driver, Duration.ofSeconds(15));
driver.manage().window().maximize();
driver.get("http://dummyweb.com");
}
#AfterMethod
public void teardown() {
driver.close();
}
}
And here is the actual TestClass:
package tests;
import static org.testng.Assert.assertEquals;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import Pages.HomePage_ListOfItems;
import Pages.LoginPage;
public class LoginTestCases extends BaseTest{
LoginPage loginpage = new LoginPage(driver, wait);
private String username = "nasir.n#planet.com";
private String password = "123456";
#Test(priority=0)
public void Valid_Login_To_AMS() {
loginpage.LoginToAMS(username, password);
}
#Test(priority=1)
public void Empty_Login_To_AMS() {
loginpage.LoginToAMS("","");
loginpage.EmptyLoginVerification("Both Password and user name are required.");
}
#Test(priority=2)
public void UserName_EmptyPassword() {
loginpage.LoginToAMS(username,"");
loginpage.EmptyPasswordVerification("Both Password and user name are required.");
}
#Test(priority=4)
public void EmptyUserName_PasswordFill( ) {
loginpage.LoginToAMS("", password);
loginpage.EmptyUserNameVerification("Both Password and user name are required.");
}
}
The errors that I am getting are below:
[RemoteTestNG] detected TestNG version 7.4.0
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 101.0.4951.41 (93c720db8323b3ec10d056025ab95c23a31997c9-refs/branch-heads/4951#{#904}) on port 52405
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
May 30, 2022 8:45:44 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
May 30, 2022 8:45:44 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 101, so returning the closest version found: a no-op implementation
May 30, 2022 8:45:44 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Unable to find CDP implementation matching 101.
May 30, 2022 8:45:44 PM org.openqa.selenium.chromium.ChromiumDriver lambda$new$3
WARNING: Unable to find version of CDP to use for . You may need to include a dependency on a specific version of the CDP using something similar to `org.seleniumhq.selenium:selenium-devtools-v86:4.1.1` where the version ("v86") matches the version of the chromium-based browser you're using and the version number of the artifact is the same as Selenium's.
Starting ChromeDriver 101.0.4951.41 (93c720db8323b3ec10d056025ab95c23a31997c9-refs/branch-heads/4951#{#904}) on port 50748
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
May 30, 2022 8:46:30 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
May 30, 2022 8:46:31 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 101, so returning the closest version found: a no-op implementation
May 30, 2022 8:46:31 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Unable to find CDP implementation matching 101.
May 30, 2022 8:46:31 PM org.openqa.selenium.chromium.ChromiumDriver lambda$new$3
WARNING: Unable to find version of CDP to use for . You may need to include a dependency on a specific version of the CDP using something similar to `org.seleniumhq.selenium:selenium-devtools-v86:4.1.1` where the version ("v86") matches the version of the chromium-based browser you're using and the version number of the artifact is the same as Selenium's.
FAILED CONFIGURATION: #BeforeMethod setup
org.openqa.selenium.WebDriverException: unknown error: cannot determine loading status
from disconnected: unable to send message to renderer
(Session info: chrome=101.0.4951.67)
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'NASIR-S-LTP', ip: '192.168.10.18', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [afb96e2642d9f544c41d7d722caab5d3, get {url=http://dev-ims.dplit.com/}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 101.0.4951.67, chrome: {chromedriverVersion: 101.0.4951.41 (93c720db8323..., userDataDir: C:\Users\nasir.n\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:53544}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://localhost:53544/devtoo..., se:cdpVersion: 101.0.4951.67, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: afb96e2642d9f544c41d7d722caab5d3
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:312)
at tests.BaseTest.setup(BaseTest.java:29)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:700)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:527)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:794)
at org.testng.TestRunner.run(TestRunner.java:596)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>amsdev</groupId>
<artifactId>ams</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
When I copy paste your code, I see the system property is set wrong. The correct one should be
System.setProperty("webdriver.chrome.driver", "C:\\UserTemp\\tools\\chrome\\chromedriver.exe");
Notice the small cases here.
Second thing I did was to Initialize the LoginPage In every test method. Else it become null and throws null pointer exception.
#Test(priority = 4)
public void EmptyUserName_PasswordFill() {
LoginPage loginpage = new LoginPage(driver, wait);
loginpage.LoginToAMS("", password);
loginpage.EmptyUserNameVerification("Both Password and user name are required.");
}
I did not had chrome so downloaded the latest version
and corresponding driver.
ChromeDriver 102.0.5005.61
For me all the 3 test cases passes, except the first one where the authentication is not successful.
Please note that I had edge browser and with correct driver, the test passes in edge as well.
The loginPage instance to be created in all the test methods is the change I did to solve the null pointer exception.
Some addition answering "why LoginPage instance needs to be created in all test methods?". You should initialize your page object after your driver has been initialized.
In your example TestNg creates an instance of your test class where the field
LoginPage loginpage = new LoginPage(driver, wait);
is initialized right away. By that moment your set up method has not yet been executed hence you pass null as driver to your page object.

Selenium No such element exception despite not using or calling the WebElement [duplicate]

This question already has answers here:
NoSuchElementException, Selenium unable to locate element
(3 answers)
Closed 1 year ago.
Now I am executing a test case but am getting a NoSuchElementException despite not using that element in my test case. Here is my implementation.
This is my page layer
public class NotificationsPage extends BasePage {
private final WebElement datePicker =
driver.findElement(By.xpath("(//input[#aria-label='Password2'])[1]"));
public String textBoxData = "";
public String date1 = "";
public String date2 = "";
private final WebElement notificationTitle = driver.findElement(By.xpath("//a[#class='pmd-list-title']"));
{
textBoxData = datePicker.getAttribute("value");
String[] parts = textBoxData.split("-");
date1 = parts[0].trim();
date2 = parts[1].trim();
}
public String getNotificationTitle()
{
String title = notificationTitle.getText();
return title;
}
}
This is my test case I'm executing
#Test
public void testDateSettings(Map<String, String> map) throws Exception
{
try
{
new LoginPage().clickLoginButton().setUserName(map.get("username")).setPassword(map.get("password")).clickSubmit()
.clickHighlights();
}
catch(ExceptionInInitializerError ex)
{
ex.printStackTrace();
}
NotificationsPage notificationsPage = new NotificationsPage();
String systemDate = DateTimeUtils.getSystemDate();
System.out.println("System date:: "+systemDate);
System.out.println("Date1:: "+notificationsPage.date1);
System.out.println("Date2:: "+notificationsPage.date2);
Assertions.assertThat(systemDate).isBetween(notificationsPage.date1, notificationsPage.date2);
}
Now as you can see I am nowhere using the element notificationTitle in this particular test case but it is still giving me NoSuchElementException for that WebElement. Here is the stack trace
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//a[#class='pmd-list-title']"}
(Session info: chrome=94.0.4606.81)
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-R3JT7MO', ip: '192.168.0.103', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '16.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 94.0.4606.81, chrome: {chromedriverVersion: 94.0.4606.61 (418b78f5838ed..., userDataDir: C:\Users\CHINMA~1\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:65399}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: b059694161fd932a928a64dc2c56d31d
*** Element info: {Using=xpath, value=//a[#class='pmd-list-title']}
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:428)
at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
at com.digicorp.pageobjects.NotificationsPage.<init>(NotificationsPage.java:15)
at com.digicorp.pageobjects.HomePage.clickHighlights(HomePage.java:77)
at com.digicorp.testcases.TC_HighlightsSection.testDateSettings(TC_HighlightsSection.java:37)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:598)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:794)
at org.testng.TestRunner.run(TestRunner.java:596)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Can someone shed some light on where I am making a mistake.
You should not declare like this,
private final WebElement notificationTitle = driver.findElement(By.xpath("//a[#class='pmd-list-title']"));
whenever the class is initializing, driver will start find this element, then resulted as NoSuchElementException
Declare the by and call it whereever you need,
private final By notificationTitleTxt = By.xpath("//a[#class='pmd-list-title']");
call this like on your method,
driver.findElement(notificationTitleTxt).getText();
What I would do here is
Use try-catch
Use findElements
Sample code for findElements
private final List<WebElement> notificationTitle = driver.findElements(By.xpath("//a[#class='pmd-list-title']"));
and in your instance initialize block
public String getNotificationTitle()
{
String title = notificationTitle.get(0).getText();
return title;
}
or why not simply try and catch block ?
try {
private final WebElement notificationTitle =
driver.findElement(By.xpath("//a[#class='pmd-list-title']"));
}
catch(ExceptionInInitializerError ex){
ex.printStackTrace();
}

Unable to initialise using #FindBy in selenium webdriver java

I am trying to perform basic selenium operations using page object pattern. However, when I run the test, I see browser being opened along with given url, but fails the test by complaining it couldn't initialise the declared web element. Can some one please help me to understand what I'm missing here. Below are my base class, page object class and test class.
BasePage
public class Basepage {
public static WebDriver driver;
public Basepage(){}
public Basepage(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver,this);
}
public void OpenBrowser(){
System.setProperty("webdriver.chrome.driver",
"C:\\SeleniumWork\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.navigate().to("https://www.google.com");
}
Page object class
public class SecurityMainPage extends Basepage{
public SecurityMainPage(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver,this);
}
#FindBy( xpath = "//a[text()='What We Do']")
WebElement dropdown;
public void selectOption(String option){
Actions actions = new Actions(driver);
actions.moveToElement(dropdown).click().build().perform(); //dropdown element is returning null
}
TestClass
public class SecurityMainPageTests extends Basepage {
protected static SecurityMainPage sec = new SecurityMainPage(driver);
public SecurityMainPageTests(){}
#BeforeTest
public void setup(){
OpenBrowser();
}
#Test
public void selectOptionTest(){
sec.selectOption("Networking");
}
#AfterTest
public void tearDown(){
closeBrowser();
}
Log
org.openqa.selenium.json.JsonException: java.lang.reflect.InvocationTargetException
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'
System info: host: 'LAPTOP-5J2KPMM3', ip: '192.168.0.36', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.7'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.json.JsonOutput.convertUsingMethod(JsonOutput.java:302)
at org.openqa.selenium.json.JsonOutput.lambda$new$13(JsonOutput.java:139)
at org.openqa.selenium.json.JsonOutput$SafeBiConsumer.accept(JsonOutput.java:394)
at org.openqa.selenium.json.JsonOutput.write(JsonOutput.java:248)
at org.openqa.selenium.json.JsonOutput.lambda$null$18(JsonOutput.java:152)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.openqa.selenium.json.JsonOutput.lambda$new$19(JsonOutput.java:152)
at org.openqa.selenium.json.JsonOutput$SafeBiConsumer.accept(JsonOutput.java:394)
at org.openqa.selenium.json.JsonOutput.write(JsonOutput.java:248)
at org.openqa.selenium.json.JsonOutput.lambda$null$20(JsonOutput.java:161)
at com.google.common.collect.SingletonImmutableBiMap.forEach(SingletonImmutableBiMap.java:65)
at org.openqa.selenium.json.JsonOutput.lambda$new$21(JsonOutput.java:160)
at org.openqa.selenium.json.JsonOutput$SafeBiConsumer.accept(JsonOutput.java:394)
at org.openqa.selenium.json.JsonOutput.write(JsonOutput.java:248)
at org.openqa.selenium.json.JsonOutput.write(JsonOutput.java:239)
at org.openqa.selenium.json.Json.toJson(Json.java:42)
at org.openqa.selenium.remote.http.AbstractHttpCommandCodec.encode(AbstractHttpCommandCodec.java:227)
at org.openqa.selenium.remote.http.AbstractHttpCommandCodec.encode(AbstractHttpCommandCodec.java:117)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:152)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.perform(RemoteWebDriver.java:614)
at org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:638)
at test.java.SecurityMainPage.selectOption(SecurityMainPage.java:37)
at test.java.SecurityMainPageTests.selectOptionTest(SecurityMainPageTests.java:28)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1191)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1116)
at org.testng.TestNG.run(TestNG.java:1024)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:110)
Suppressed: org.openqa.selenium.json.JsonException: Attempting to close incomplete json stream
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.json.JsonOutput.close(JsonOutput.java:263)
at org.openqa.selenium.json.Json.toJson(Json.java:44)
... 32 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.openqa.selenium.json.JsonOutput.convertUsingMethod(JsonOutput.java:298)
... 47 more
Caused by: java.lang.NullPointerException
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at com.sun.proxy.$Proxy9.getWrappedElement(Unknown Source)
at org.openqa.selenium.interactions.PointerInput$Origin.asArg(PointerInput.java:203)
at org.openqa.selenium.interactions.PointerInput$Move.encode(PointerInput.java:154)
at org.openqa.selenium.interactions.Sequence.encode(Sequence.java:75)
at org.openqa.selenium.interactions.Sequence.toJson(Sequence.java:84)
... 52 more
For easy understanding, I split the driver initiation and navigation to url to two methods in Basepage. And you haven't declared the closeBrowser() method.
Base Class
public class Basepage {
public static WebDriver driver;
public Basepage(){}
public Basepage(WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver,this);
}
public WebDriver initiateDriver(){
System.setProperty("webdriver.chrome.driver",
"C:\\SeleniumWork\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
return driver;
}
public void openBrowser(String url){
driver.navigate().to(url);
}
}
Test Class
public class SecurityMainPageTests extends Basepage {
WebDriver driver = null;
protected static SecurityMainPage sec = null;
String url = "https://www.google.com";
public SecurityMainPageTests(){}
#BeforeTest
public void setup(){
driver = initiateDriver();
openBrowser(String url);
sec = new SecurityMainPage(driver);
}
#Test
public void selectOptionTest(){
sec.selectOption("Networking");
}
#AfterTest
public void tearDown(){
closeBrowser();
}
}

how to solve Selenium ChromeDriver Timed out receiving message from renderer exception

I'm getting the below error while page transition, by clicking on submit button. It looks like there was an issue with the newest Chrome release. Without the disable-gpu Chromeoption set, the renderer will occasionally timeout. The workaround until Google fixes this (if they do fix it at all) is to add the --disable-gpu attribute to the ChromeOptions.
Error-message:
Launching the chrome driver
Starting ChromeDriver 2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e) on port 8737
Only local connections are allowed.
Aug 22, 2018 10:02:06 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
[1534912350.875][SEVERE]: Timed out receiving message from renderer: 20.000
[1534912350.881][SEVERE]: Timed out receiving message from renderer: -0.010
iiiiiiiiiiiiiiiiiii
[1534912370.909][SEVERE]: Timed out receiving message from renderer: 20.000
[1534912370.909][SEVERE]: Timed out receiving message from renderer: -0.001
Exception in thread "main" org.openqa.selenium.TimeoutException: timeout
(Session info: chrome=68.0.3440.106)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:05:20.749Z'
System info: host: 'LAPTOP-B3DIN1KF', ip: '192.168.43.235', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.41.578737 (49da6702b16031..., userDataDir: C:\Users\ACER-S~1\AppData\L...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:49380}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 68.0.3440.106, webStorageEnabled: true}
Session ID: b3de58666d2ca24706dc70a9d78094e4
*** Element info: {Using=css selector, value=body > div > div > div > h1 > a}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:322)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:416)
at org.openqa.selenium.By$ByCssSelector.findElement(By.java:431)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:314)
at demoPackage.Demo.main(Demo.java:102)
Using the script:
package demoPackage;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import com.codoid.products.exception.FilloException;
/**
* #author Acer-sumit
*
*/
public class Demo {
public static WebDriver driver = null;
public static JavascriptExecutor js;
public static void main(String args[]) throws FilloException, InterruptedException {
System.out.println("Launching the chrome driver ");
// Set the chrome driver exe file path
System.setProperty("webdriver.chrome.driver","E:\\selenium_sumit\\chromedriver_win32_2.40\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-gpu");
options.addArguments("--disable-browser-side-navigation");
// Instantiate the chrome driver
driver = new ChromeDriver(options);
///System.setProperty("webdriver.edge.driver","E:\\MicrosoftWebDriver.exe");
//driver = new EdgeDriver();
//driver.manage().timeouts().implicitlyWait(6000, TimeUnit.MILLISECONDS);
driver.manage().timeouts().pageLoadTimeout(20,TimeUnit.SECONDS);
//driver.manage().timeouts().setScriptTimeout(60, TimeUnit.SECONDS);
// set the browser URL in get() to load the webpage
try {
driver.navigate().to("https://diggza.com/");
driver.findElement(By.cssSelector("input[name='url']")).clear();
driver.findElement(By.cssSelector("input[name='url']")).sendKeys("https://www.google.com/");
driver.findElement(By.cssSelector("input[name='email']")).sendKeys("sdsjsnssk#gmail.com");
driver.findElement(By.cssSelector("#myform > p:nth-child(5) > a:nth-child(1)")).click();
//wait for element to be visible and perform click
//wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[type='submit']")));
js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", driver.findElement(By.cssSelector("input[type='submit']")));
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("iiiiiiiiiiiiiiiiiii");
driver.findElement(By.cssSelector("body > div > div > div > h1 > a")).click();
//driver.navigate().refresh();
}
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
System.out.println("-------fffffffffff---------");
driver.get("https://diggza.com/");
driver.findElement(By.cssSelector("input[name='url']")).clear();
driver.findElement(By.cssSelector("input[name='url']")).sendKeys("https://www.google.com/");
driver.findElement(By.cssSelector("input[name='email']")).sendKeys("sumit.pradhan96#gmail.com");
driver.findElement(By.cssSelector("#myform > p:nth-child(5) > a:nth-child(1)")).click();
//wait for element to be visible and perform click
//wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[type='submit']")));
driver.findElement(By.cssSelector("input[type='submit']")).click();
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
}

Categories