Action class is not locatable in Selenium - java

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class test {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/Users/alcodesmobility/Desktop/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://www.browserstack.com/");
Actions action = new Actions(driver);
WebElement element = driver.findElement(By.linkText("Get started free"));
action.moveToElement(element).click();
//using click action method
}
}
Starting ChromeDriver 89.0.4389.23
(61b08ee2c50024bab004e48d2b1b083cdbdac579-refs/branch-heads/4389#{#294})
on port 24715 Only local connections are allowed. Please see
https://chromedriver.chromium.org/security-considerations for
suggestions on keeping ChromeDriver safe. ChromeDriver was started
successfully. [1622542783.292][WARNING]: This version of ChromeDriver
has not been tested with Chrome version 90. Jun 01, 2021 3:49:43 PM
org.openqa.selenium.remote.ProtocolHandshake createSession INFO:
Detected dialect: W3C Exception in thread "main"
java.lang.ClassCastException: class
org.openqa.selenium.remote.RemoteWebElement cannot be cast to class
org.openqa.selenium.interactions.internal.Locatable
(org.openqa.selenium.remote.RemoteWebElement and
org.openqa.selenium.interactions.internal.Locatable are in unnamed
module of loader 'app') at
org.openqa.selenium.interactions.Actions.moveToElement(Actions.java:387)
at CronberrySignin.test.main(test.java:22)

I guess you are missing completing the move to element code line.
Try this instead:
action.moveToElement(element).click(element).build().perform();

There is no need to implement Actions class, the element is in Selenium viewport right from the page loading.
use id instead.
driver.findElement(By.id("signupModalButton")).click();
Read when to use actions class here
and by reading exception stack trace, it looks like driver issue. Make sure to use inline version of Selenium webdriver, chromedriver, and chrome broswer.

Related

java.lang.IllegalMonitorStateException (java selenium)

package main_files;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class main_downloader {
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.gecko.driver", "path\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.wait(1);
driver.get("https://www.google.com/");
driver.wait(5);
driver.quit();
}
}
for some reason when I try to run this code it gives me this Error
1597445198205 geckodriver INFO Listening on 127.0.0.1:7834
1597445198836 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\ahmed\\AppData\\Local\\Temp\\rust_mozprofileinTqzS"
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
console.error: SearchCache: "_readCacheFile: Error reading cache file:" (new Error("", "(unknown module)"))
1597445201342 Marionette INFO Listening on port 22663
1597445201445 Marionette WARN TLS certificate errors will be ignored for this session
Aug 15, 2020 1:46:41 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Exception in thread "main" java.lang.IllegalMonitorStateException
at java.lang.Object.wait(Native Method)
at main_files.main_downloader.main(main_downloader.java:10)
i've tried some solutions but nothing worked !, could anyone help please !? Thx.
wait() function call must be called from Synchronized block to avoid this exception.
Do you want to sleep the main thread , if yes please use Thread.sleep() instead of wait() function call.

How to address the log INFO Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()` in selenium project

I just started a selenium project, but things didn't got right, so after searching a bit I found this solution. It works but i can't understand what these red statements want me to do, or how to get rid of them.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.*;
public class SelTest1
{
public static void main(String [] args)
{
System.setProperty("webdriver.gecko.driver","X:\\Gecko\\geckodriver-v0.24.0-win64\\geckodriver.exe");
File pathBinary = new File("X:\\FireFoxx\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
DesiredCapabilities desired = DesiredCapabilities.firefox();
FirefoxOptions options = new FirefoxOptions();
desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxBinary));
WebDriver obj = new FirefoxDriver(options);
obj.get("http://www.google.com/");
}
}
I got the result i wanted, but I don't understand the warning{ red statements}
I am putting those red lines { warnings here too for ease }
Jul 12, 2019 7:07:28 PM org.openqa.selenium.remote.DesiredCapabilities firefox
INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
1562938650997 mozrunner::runner INFO Running command: "X:\\FireFoxx\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\adars\\AppData\\Local\\Temp\\rust_mozprofile.uTUmeENutxin"
1562938652637 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1562938652638 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1562938652638 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: about:reader*
1562938655909 Marionette INFO Listening on port 50040
1562938655964 Marionette WARN TLS certificate errors will be ignored for this session
Jul 12, 2019 7:07:36 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
This INFO log message:
INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
is the result of the changes incorporated in:
Selenium v3.0.0-beta4
Added ability to use FirefoxOptions when starting firefox.
Selenium v3.5.0
* Start making *Option classes instances of Capabilities. This allows
the user to do:
`WebDriver driver = new RemoteWebDriver(new InternetExplorerOptions());`
If your usecase is to explicitly mention the absolute location of the FirefoxBinary you can use the following solution:
Using FirefoxOptions:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
public class A_Firefox_binary
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver(options);
driver.get("https://stackoverflow.com");
System.out.println("Page Title is : "+driver.getTitle());
driver.quit();
}
}
Console Output:
Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers

Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.io.FileHandler.unzip(Ljava/io/InputStream;)Ljava/io/File;

I'm trying to run selenium webdriver program, getting following error :
Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.io.FileHandler.unzip(Ljava/io/InputStream;)Ljava/io/File;
Firefox version : 47.0.1
Selenium version : 2.53.1
Eclipse : Oxygen Release (4.7.0)
import org.apache.xpath.XPathContext;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class PG1
{
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://demo.guru99.com/selenium/newtours/");
System.out.println("The title of page is : " + driver.getTitle());
driver.close();
}
}
This program was working fine in another laptop, but not working on new laptop/setup.
Can someone please help.
Error I'm getting :
Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.io.FileHandler.unzip(Ljava/io/InputStream;)Ljava/io/File;
at org.openqa.selenium.firefox.internal.FileExtension.obtainRootDirectory(FileExtension.java:82)
at org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:59)
at org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:64)
at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:443)
at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:421)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:85)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.startClient(RemoteWebDriver.java:303)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:125)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:218)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:207)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at bitbfw.PG1.main(PG1.java:11)
Found what was wrong..
it was that in "Java Build Path", the JRE system library was not added earlier. I went to configure Build path-->Add Jars selected "jRE system library", Applied & Closed.
Then on all the programs worked fine.

Detected borken kqueue while running the Java code in Selenium

I am getting the following problems with Selenium Test Run. I am using the tests to create and run on macSierra (10.12) Processor 2.8 GHz Intel Core i7.
I have installed Eclipse, Selenium and Java files from Selenium site.
Here is my code :
package com.some.seleniumproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.*;
import org.openqa.selenium.WebDriver.*;
import org.openqa.selenium.firefox.*;
public class sampleTest1 {
public static void main (String[] args) {
System.setProperty("webdriver.gecko.driver", "//Library/Java/geckodriver");
WebDriver driver=new FirefoxDriver();
String baseUrl = "http://www.seleniumhq.org";
String et = "Selenium - Web Browser Automation";
driver.get(baseUrl);
String rt = driver.getTitle();
if (rt.contentEquals(et)) {
System.out.println("Title is matched");
}
else {
System.out.println("Title is not matched");
}
driver.close();
}
}
Here are the errors :
1 :
1477536446864 geckodriver INFO Listening on 127.0.0.1:11419
Oct 26, 2016 7:47:27 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1477536448247 mozprofile::profile INFO Using profile path /var/folders/dk/xyw6v2zd1bd5sp8pd_4f8fpw0000gn/T/rust_mozprofile.jDvUQye5JfoO
1477536448249 geckodriver::marionette INFO Starting browser /Applications/Firefox.app/Contents/MacOS/firefox-bin
1477536448307 geckodriver::marionette INFO Connecting to Marionette on localhost:56571
[warn] kq_init: detected broken kqueue; not using.: Undefined error: 0
1477536450843 Marionette INFO Listening on port 56571
1477536453622 Marionette INFO startBrowser dab7ebb7-1664-6943-9cc4-e3817dd3a894
Oct 26, 2016 7:47:34 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[warn] kq_init: detected broken kqueue; not using.: Undefined error: 0
However, the above error maybe, correct result is thrown in the output.
2 :
Note: This element has neither has attached source nor attached Java doc and hence no Java
doc could be found. - this is for the step driver.close();
Please help.
I've found this bug reported in Mozilla - https://bugzilla.mozilla.org/show_bug.cgi?id=1304266. Read a comment to it.
It looks like libevent issue can cause the problem you've described.

Using Appium to automate Mobile Safari on real device and encountering uncaught exceptions

Using latest appium version to communicate to my fully provisioned iOS 7 device.
I can get Webdriver to build and and talk to my appium server.
I can get SafariLauncher to build from xcode and run on my device.
But when I try to use my java code to use the appium server to call SafariLauncher and run it on my device- I get the following "uncaughtException"
I've tried letting appium use its own version of SafariLauncher and I get a slightly different but no less blocking error that states "a new session could not be created". After switching the desired capabilities to my own locally built version of SafariLauncher.app, I'm getting the fresh "uncaughtException" error.
*info: Welcome to Appium v0.14.2
info: Appium REST http interface listener started on 0.0.0.0:3001
info - socket.io started
info: Spawning instruments force-quitting watcher process
info: [FQInstruments] Force quit unresponsive instruments v0.0.1
info: Responding to client with success: {"status":0,"value":{"build":{"version":"0.14.2","revision":"113e796b850b28e7066fe472faf8554b73b6299d"}}}
debug: Appium request initiated at /wd/hub/status
GET /wd/hub/status 200 8ms - 144b
debug: Request received with params: {}
debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"desiredCapabilities":{"app":"/Users/accesso/Library/Developer/Xcode/DerivedData/SafariLauncher-cquscfvgyludjdaolkpikgbmowez/Build/Products/Debug-iphoneos/SafariLauncher.app","device":"iphone"}}
info: Using local app from desiredCaps: /Users/accesso/Library/Developer/Xcode/DerivedData/SafariLauncher-cquscfvgyludjdaolkpikgbmowez/Build/Products/Debug-iphoneos/SafariLauncher.app
info: Creating new appium session a84fee15-6d72-41d2-8ebb-4c8860455c2a
info: Removing any remaining instruments sockets
info: Cleaned up instruments socket /tmp/instruments_sock
warn: Could not parse plist file at /Users/accesso/Library/Developer/Xcode/DerivedData/SafariLauncher-cquscfvgyludjdaolkpikgbmowez/Build/Products/Debug-iphoneos/SafariLauncher.app/en.lproj/Localizable.strings
info: Not setting locale because we're using a real device
info: Not setting iOS and app preferences since we're on a real device
info: Starting iOS device log capture via idevicesyslog
info: Not setting device type since we're connected to a device
error: uncaughtException: undefined date=Thu Feb 06 2014 10:17:25 GMT-0500 (EST), pid=3350, uid=501, gid=20, cwd=/Applications/Appium.app/Contents/Resources/node_modules/appium, execPath=/Applications/Appium.app/Contents/Resources/node/bin/node, version=v0.10.17, argv=[/Applications/Appium.app/Contents/Resources/node/bin/node, /Applications/Appium.app/Contents/Resources/node_modules/appium/lib/server/main.js, --port, 3001, --app, /, --udid, 7cc3dc5cc930406e9ce0e9f721a8e21b1eadfebc, --session-override, --keep-artifacts], rss=46399488, heapTotal=34235136, heapUsed=17620112, loadavg=[1.60546875, 1.29833984375, 1.205078125], uptime=84958, trace=[], stack=undefined*
Here is the script I'm trying to run-
import static org.junit.Assume.assumeTrue;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
#RunWith(JUnit4.class)
public class test {
WebDriver driver;
private static boolean isSupportedPlatform() {
Platform current = Platform.getCurrent();
return Platform.MAC.is(current) || Platform.WINDOWS.is(current);
}
#Before
synchronized public void createDriver() {
assumeTrue(isSupportedPlatform());
try {
//setup the web driver and launch the webview app.
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("app", "/Users/accesso/Library/Developer/Xcode/DerivedData/SafariLauncher-cquscfvgyludjdaolkpikgbmowez/Build/Products/Debug-iphoneos/SafariLauncher.app");
desiredCapabilities.setCapability("device", "iphone");
URL url = new URL("http://0.0.0.0:3001/wd/hub");
driver = new RemoteWebDriver(url, desiredCapabilities);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
#After
public void quitDriver() {
driver.quit();
}
#Test
public void shouldBeAbleToPerformAGoogleSearch() {
driver.get("http://store.accesso.com/CF-KBF");
}
}
Try Appium latest 15 version.
I faced same problem of "error: uncaughtException: undefined date" updating Appium version resolved it.
I was using MAC mini and IPAD with APPIUM.

Categories

Resources