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));
}
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
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.
I was trying to run this on the Android TV i see the Appium is able to click on all the buttons and input the data in text box except the very first one. i have to click on it then wait and used send keys to see if it solves the issue but no luck. can someone help me on this.enter image description here
Base.Java
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;
public class Base {
public static AndroidDriver<AndroidElement> capabalities() throws MalformedURLException {
File file = new File ("src");
File fs = new File(file,"TVTestApp_ct.apk");
DesiredCapabilities capabalities = new DesiredCapabilities();
capabalities.setCapability(MobileCapabilityType.AUTOMATION_NAME,"uiautomator2");
capabalities.setCapability(MobileCapabilityType.DEVICE_NAME, "Automation");
capabalities.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),capabalities);
return driver;
}
}
HomeScreen.Java
import java.net.MalformedURLException;
import org.openqa.selenium.By;
import org.openqa.selenium.By.ByClassName;
import org.openqa.selenium.StaleElementReferenceException;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
public class HomeScreen extends Base {
public static void main(String[] args) throws MalformedURLException, InterruptedException {
AndroidDriver<AndroidElement> driver = capabalities();
driver.findElementById("com.tvexample.tvtestapp:id/editText").sendKeys("1234");
driver.findElementById("com.tvexample.tvtestapp:id/editText1").sendKeys("1234")
}
}
Logs:
Jun 21, 2021 2:11:47 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: androidx.test.uiautomator.StaleObjectException
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:25:48'
System info: host: 'TXCDTL20CT1696', ip: '135.70.71.74', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.2'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {app: C:\Users\cg517n\Documents\e..., appPackage: com.tvexample.tvtestapp, automationName: uiautomator2, databaseEnabled: false, desired: {app: C:\Users\cg517n\Documents\e..., automationName: uiautomator2, deviceName: Automation, platformName: android}, deviceApiLevel: 28, deviceManufacturer: unknown, deviceModel: sdk_google_atv_x86, deviceName: emulator-5554, deviceScreenDensity: 320, deviceScreenSize: 1920x1080, deviceUDID: emulator-5554, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, pixelRatio: 2, platform: LINUX, platformName: Android, platformVersion: 9, statBarHeight: 0, takesScreenshot: true, viewportRect: {height: 1080, left: 0, top: 0, width: 1920}, warnings: {}, webStorageEnabled: false}
Session ID: 75f6f7db-21e8-407e-8a53-59271e4e9e02
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
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 io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:247)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:45)
at io.appium.java_client.MobileElement.execute(MobileElement.java:1)
at io.appium.java_client.android.AndroidElement.execute(AndroidElement.java:1)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:106)
at HomeScreen.main(HomeScreen.java:18)
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);
}
}
OS : Windows 10
Browser : Firefox 61
Selenium Version 3.13
Code :
package PhpTravelsPackage;
//import java.awt.List;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.By.ByClassName;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxDriverLogLevel;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.WebElement;
public class phpTravels {
public static void main (String args[]) {
System.setProperty("webdriver.gecko.driver","C:\\\\Marionette\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setLogLevel(FirefoxDriverLogLevel.DEBUG);
WebDriver driver = new FirefoxDriver(options);
driver.get ("https://www.phptravels.net/");
WebElement link = null;
int linksCount = 0 ;
Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.id("li_myaccount"))).perform();
}
}
Error :
(Program successfully opens the website, but does not perform the action instructed)
Exception in thread "main" org.openqa.selenium.WebDriverException: TypeError: rect is undefined
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:32:14.902Z'
System info: host: 'ADMIN-PC', ip: '192.168.1.7', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 61.0.1, javascriptEnabled: true, moz:accessibilityChecks: false, moz:headless: false, moz:processID: 9652, moz:profile: C:\Users\admin\AppData\Loca..., 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: a8b8b5b6-d384-4c35-80f6-9d32bdaa428c
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.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:548)
at org.openqa.selenium.remote.RemoteWebDriver.perform(RemoteWebDriver.java:614)
at org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:638)
at org.openqa.selenium.interactions.Actions.perform(Actions.java:594)
at PhpTravelsPackage.phpTravels.main(phpTravels.java:30)
If you want to click on My account button after opening the URL, Then you can try this code:
Note that this id li_myaccount is not unique. There are two web element present in DOM.
WebElement myAccount = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#id='collapse']/descendant::ul[3]/li[#id='li_myaccount']/a")));
myAccount.click();