I have written a scrapper using selenium which uses chrome driver. It works well but some time it fails to quit chrome driver with following exception
org.openqa.selenium.WebDriverException: Timed out waiting for driver server to stop.
Build info: version: '4.1.3', revision: '7b1ebf28ef'
System info: host: '45-79-216-229.ip.linodeusercontent.com', ip: '45.79.216.229', os.name: 'Linux', os.arch: 'amd64', os.version: '4.18.0-348.12.2.el8_5.x86_64', java.version: '11.0.14'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [66aa12cc87af0a6cf095436a6bbece90, quit {}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 102.0.5005.61, chrome: {chromedriverVersion: 102.0.5005.61 (0e59bcc00cc4..., userDataDir: /tmp/.com.google.Chrome.DhJaWB}, goog:chromeOptions: {debuggerAddress: localhost:45009}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, proxy: Proxy(), se:cdp: ws://localhost:45009/devtoo..., se:cdpVersion: 102.0.5005.61, 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: 66aa12cc87af0a6cf095436a6bbece90
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:132)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:567)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:622)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:626)
at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:463)
at org.openqa.selenium.chromium.ChromiumDriver.quit(ChromiumDriver.java:293)
Code
I am adding my code here.
public class SeleniumScraper {
private WebDriver driver;
public SeleniumScraper() {
WebDriverManager.chromedriver().setup();
ChromeOptions options = this.getDefaultChromeOptions();
this.driver = new ChromeDriver(options);
driver.manage().window().maximize();
}
public WebDriver getPage(String url) {
this.driver.get(url);
return driver;
}
public boolean quitDriver() {
this.driver.quit();
return true;
}
protected ChromeOptions getDefaultChromeOptions() {
HashMap<String, Object> chromePrefs = new HashMap<>(2);
chromePrefs.put("profile.default_content_settings.popups", false);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
options.setHeadless(true);
return options;
}
}
I tried
driver.close();
driver.quit();
it does not throw any exception now.
Related
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
Code Trail
WebElement parentTextBox = driver.findElement(By.id("name"));
parentTextBox.sendKeys("This is parent textbox");
WebElement newWindowBtn = driver.findElement(By.id("newWindowBtn"));
newWindowBtn.click();
String parentWindow = driver.getWindowHandle();
Set<String> getWindows = driver.getWindowHandles();
for (String handles : getWindows) {
if (!handles.equals(parentWindow))
{
driver.switchTo().window(handles);
driver.manage().window().maximize();
WebElement firstName = driver.findElement(By.id("firstName"));
firstName.sendKeys("Pankaj");
}
Thread.sleep(10000);
//driver.switchTo().window(parentWindow);
//driver.switchTo().window("");
driver.switchTo().defaultContent();
Thread.sleep(5000);
parentTextBox.clear();
parentTextBox.sendKeys("switching back to parent window is success");
Error
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
(Session info: chrome=105.0.5195.126)
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-9GE1TC7', ip: '192.168.1.6', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 105.0.5195.126, chrome: {chromedriverVersion: 105.0.5195.52 (412c95e51883..., userDataDir: C:\Users\Admin\AppData\Loca...}, goog:chromeOptions: {debuggerAddress: localhost:65092}, 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: 2b22a0d3f499205579e31a39c1233d25
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.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.RemoteWebElement.execute(RemoteWebElement.java:285)
at org.openqa.selenium.remote.RemoteWebElement.clear(RemoteWebElement.java:124)
at switchWindows.SwitchWindows.main(SwitchWindows.java:58)
My code:
System.setProperty("webdriver.chrome.driver", "F:\\Eclipse1\\Selenium\\SeleniumBasic\\lib\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.goibibo.com/flights/");
driver.manage().window().maximize();
Thread.sleep(1000);
System.out.println(driver.getTitle());
driver.findElement(By.xpath("//span[text()='Round trip']")).click();
Thread.sleep(1000);
driver.findElement(By.xpath("//input[#id='gosuggest_inputSrc']")).sendKeys("Coimbatore");
Thread.sleep(1500);
driver.findElement(By.xpath("//ul[#id='react-autosuggest-1']/li[1]")).click();
//or8
//driver.findElement(By.xpath("//ul[#id='react-autosuggest-1']/li[#id='react-autosuggest-1-suggestion--0']")).click();
driver.findElement(By.xpath("//input[#id='gosuggest_inputDest']")).sendKeys("Bangalore");
Thread.sleep(1000);
driver.findElement(By.xpath("//ul[#id='react-autosuggest-1']/li[1]")).click();
driver.findElement(By.xpath("//input[#class='inputSrch curPointFlt ' and #placeholder='Departure']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//div[#class='DayPicker-Day' and #aria-label='Mon Feb 25 2019']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//div[#class='DayPicker-Day' and #aria-label='Thu Feb 28 2019']")).click();
driver.findElement(By.xpath("//div[#class='dF whiteBg fl col-sm-5 justifyBetween ht45 alignItemsCenter brdrTpBtmRt curPointFlt width20']")).click();
Thread.sleep(1000);
for(int i=0;i<2;i++) {
driver.findElement(By.xpath("//button[#class='fl plusSpin brdrTpBtmRt' and #id='adultPaxPlus']")).click();
}
Select s=new Select(driver.findElement(By.xpath("//select[#class='custSelect width100 whiteBg padTB5 padLR10']")));
s.selectByValue("B");
driver.findElement(By.xpath("//button[#value='Search']")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//a[#href='javascript:void(0);' and #id='sortByPriceOnw']")).click();
driver.findElement(By.xpath("//i[#class='fl posAbs icon-close1 ico17 curPoint fb whiteBg closePers black']")).click();
System.out.println("hi");
Thread.sleep(1500);
driver.findElement(By.xpath("//a[#href='javascript:void(0);' and #id='sortByPriceRet']")).click();
/*Thread.sleep(1000);
driver.findElement(By.xpath("//i[#class='we_close']")).click();*/
Thread.sleep(1000);
driver.findElement(By.xpath("(//div[#class='control__indicator'])[2]")).click();
Exception:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (648, 603). Other element would receive the click:
(Session info: chrome=72.0.3626.119)
(Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),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: 'SAISHANMUKHAVAR', ip: '192.168.137.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', 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.44.609538 (b655c5a60b0b54..., userDataDir: C:\Users\gsais\AppData\Loca...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:60971}, 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: ignore, unhandledPromptBehavior: ignore, version: 72.0.3626.119, webStorageEnabled: true}
Session ID: 8279839ce42d641ca8e2c7bdefc6ab07
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: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.RemoteWebElement.execute(RemoteWebElement.java:276)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83)
at GoIbiboCLass.main(GoIbiboCLass.java:70)
For now, using the latest serenity version (2.0.2) through maven I was able to simply perform an upload action like this:
import net.serenitybdd.core.annotations.findby.By;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.actions.Upload;
import net.serenitybdd.screenplay.targets.Target;
import net.serenitybdd.screenplay.waits.WaitUntil;
import java.nio.file.Path;
import java.nio.file.Paths;
import static net.serenitybdd.screenplay.Tasks.instrumented;
import static net.serenitybdd.screenplay.matchers.WebElementStateMatchers.isVisible;
public class PerformTheUpload implements Task {
public static Target UPLOAD_SOURCE_FILES_TARGET =
Target.the("Upload source files").located(By.id("uploadSourceFiles"));
public static final String TEST_FILE = "src/main/resources/files/test.txt";
public static final Path TEST_FILE_PATH = Paths.get(TEST_FILE).toAbsolutePath();
public static PerformTheUpload onTheField() {
return instrumented(PerformTheUpload.class);
}
#Override public <T extends Actor> void performAs(T actor) {
actor.attemptsTo(WaitUntil.the(UPLOAD_SOURCE_FILES_TARGET, isVisible()));
actor.attemptsTo(Upload.theFile(TEST_FILE_PATH).to(UPLOAD_SOURCE_FILES_TARGET));
}
}
The problem with it is that it generates the following error:
org.openqa.selenium.UnsupportedCommandException: POST /session/76ec390f-dbbe-48c2-be32-931969d81210/file did not match a known command
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'TAG-614', ip: '10.10.37.89', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 62.0.3, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.22.0, moz:headless: false, moz:processID: 795608, moz:profile: C:\Users\alexandru.arcan\Ap..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 10.0, rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 76ec390f-dbbe-48c2-be32-931969d81210
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'TAG-614', ip: '10.10.37.89', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: driver.version: unknown
Can someone please point me in the right direction?
Found a solution by implementing myUploadFile method:
...
import net.thucydides.core.pages.components.FileToUpload;
public class PerformTheUpload implements Task {
private WebDriver driver;
public PerformTheUpload (WebDriver driver){
this.driver = driver;
}
public static PerformTheUpload onTheField(WebDriver driver) {
return instrumented(PerformTheUpload.class, driver);
}
#Override public <T extends Actor> void performAs(T actor) {
actor.attemptsTo(WaitUntil.the(UPLOAD_SOURCE_FILES_TARGET, isVisible()));
myUploadFile(driver);
}
public void myUploadFile(WebDriver driver){
WebElement webElement = getUploadWebElementById("uploadSourceFiles", driver);
FileToUpload fileToUpload = new FileToUpload(driver, TEST_FILE);
fileToUpload.fromLocalMachine().to(webElement);
}
}
//in the page class
public static WebElement getUploadWebElementById(String id, WebDriver driver) {
return driver.findElement(By.id(id));
}
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);
}
}