I'm trying to locate a WebElement on google.com page using Appium and AndriodDriver. Selenium throws an Exception every time I'm trying to run the code bellow.
Client:
#Test
public void mobWebAppTest() throws Exception{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("automationName", "Appium");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.3");
capabilities.setCapability("deviceName", "4df12fbe651cafd3");
capabilities.setCapability("appPackage", "com.android.browser");
capabilities.setCapability("appActivity", "BrowserActivity");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
AndroidDriver<WebElement> driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://www.google.com/");
driver.findElement(By.xpath("//input[#name='q']")); // the error is thrown here
driver.quit();
}
Exception Logs:
org.openqa.selenium.NoSuchElementException: An element could not be located on
the page using the given search parameters. (WARNING: The server did not
provide any stacktrace information)
Command duration or timeout: 30.31 seconds
For documentation on this error, please visit:
http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.1', revision:
'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: '*******', ip: '*******', os.name: 'Mac OS X', os.arch:
'x86_64', os.version: '10.10.5', java.version: '1.8.0_11'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.android.browser, deviceScreenSize=720x1280,
networkConnectionEnabled=true, warnings={}, databaseEnabled=false,
deviceName=4df12fbe651cafd3, platform=LINUX, deviceUDID=4df12fbe651cafd3,
appActivity=BrowserActivity, desired={appPackage=com.android.browser,
appActivity=BrowserActivity, platformVersion=4.3, automationName=Appium,
browserName=Android, platformName=Android, deviceName=4df12fbe651cafd3},
platformVersion=4.3, webStorageEnabled=false, locationContextEnabled=false,
automationName=Appium, takesScreenshot=true, browserName=Android,
javascriptEnabled=true, deviceModel=GT-I9300, platformName=Android,
deviceManufacturer=samsung}]
Session ID: c68c1f7d-0e6e-481a-a335-23ede1de7de9
*** Element info: {Using=xpath, value=//input[#name='q']}
at ...
Also, when I'm trying to get a source code of the page, I'm getting back xml (as in ui automator) of the entire screen, not HTML of the google page. Could it be the reason for the exception?
THank you.
You need to switch to the web context first for DOM-level access:
driver.context("WEBVIEW_1");
You can get all available contexts with driver.getContextHandles().
To automate the "Browser" app with Appium, you need to use desired capability "browserName": "Browser" instead of setting the appPackage & appActivity.
https://appium.io/slate/en/master/?java#appium-server-capabilities
Related
I am attempting to use the "gecko" webdriver (.17 I believe) with Selenium (v.3.4.0) to open an older version of Firefox (52.9.0 ESR) in fullscreen (NOT maximized). However, even after reviewing some questions on this website, as well as performing other research, I am still unable to open Firefox in fullscreen. My code is very simple:
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver");
String user = args[0];
String pass = args[1];
FirefoxOptions options = new FirefoxOptions();
// options.addArguments("--start-fullscreen");
// options.addArguments("--start-maximized");
// options.addArguments("--disable-infobars");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
FirefoxDriver driver = new FirefoxDriver(ffprofile);
driver.get(BASE_URL);
driver.findElement(By.name("user")).sendKeys(user);
driver.findElement(By.name("pass")).sendKeys(pass);
driver.findElement(By.id("login")).click();
}
I have tried the following:
Using a custom profile and loading two different extensions (AutoFullscreen and MPT Fullscreen).
Using driver.getKeyboard().sendKeys(Keys.F11); (throws Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: sendKeysToActiveElement
)
Looking for a command line argument to pass to the browser.
I can get this working in Chromium by simply setting an option, but have had no success with Firefox. How might I get it to work with this browser? I am using the older version of Firefox because this is running on a Rasperry PI and that seems to be the latest version supported on the device.
Thanks.
EDIT:
Output from driver.manage().window().fullscreen():
INFO: Detected dialect: W3C
Dec 11, 2018 9:07:29 AM org.openqa.selenium.remote.ErrorCodes toStatus
INFO: HTTP Status: '404' -> incorrect JSON status mapping for 'unknown error' (500 expected)
Exception in thread "main" org.openqa.selenium.WebDriverException: fullscreenWindow
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'xxx', ip: 'xxx', os.name: 'Linux', os.arch: 'arm', os.version: '4.14.79-v7+', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=/tmp/rust_mozprofile.GRnhrulj1j6l, rotatable=false, timeouts={implicit=0.0, page load=300000.0, script=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=52.9.0, platformVersion=4.14.79-v7+, moz:processID=1076.0, browserName=firefox, javascriptEnabled=true, platformName=linux}]
Session ID: 6633ed83-9a19-4e5c-9229-5fadef8a83ce
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:422)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:150)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:115)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:45)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:694)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.fullscreen(RemoteWebDriver.java:929)
at com.midamcorp.kblogin.Entry.main(Entry.java:31)
I am trying to automate appium android but the desired capability always throw error for sauce labs like:
Unable to parse remote response: Cannot specify both browserName and
app caps.
I haven't add browserName in cap still it is showing key in request JSON
I have also upload apk on server using curl command
Full error:
Exception in thread "main" org.openqa.selenium.WebDriverException:
Unable to parse remote response: Cannot specify both browserName and
app caps. Please check our platforms configurator
(https://wiki.saucelabs.com/display/DOCS/Platform+Configurator):
{'deviceName': 'Android Emulator', 'app':
'sauce-storage:HelloGappium-android.zip', 'platform': 'ANDROID',
'browserName': 'chrome', 'version': '', 'deviceType': 'phone',
'deviceOrientation': 'portrait', 'platformVersion': '4.4',
'platformName': 'Android', 'appiumVersion': '1.5.1'} Build info:
version: '3.7.1', revision: '8a0099a', time:
'2017-11-06T21:01:39.354Z' System info: host: '', ip:
'', os.name: 'Windows 10', os.arch: 'amd64', os.version:
'10.0', java.version: '1.8.0_131' Driver info: driver.version:
AndroidDriver at
org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:111)
at
org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at
org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at
io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
at
io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
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.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at
org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142)
at
io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:83) at
io.appium.java_client.AppiumDriver.(AppiumDriver.java:93) at
io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:72)
at
test.java.sauceLabs.HybridBaseSauceLabs.capabilities(HybridBaseSauceLabs.java:37)
at
test.java.sauceLabs.HybridBasetestcase.main(HybridBasetestcase.java:26)
My code:
public static AndroidDriver<AndroidElement> capabilities() throws MalformedURLException
{
DesiredCapabilities caps = DesiredCapabilities.android();
caps.setCapability("appiumVersion", "1.5.1");
caps.setCapability("deviceName","Android Emulator");
caps.setCapability("deviceType","phone");
caps.setCapability("deviceOrientation", "portrait");
caps.setCapability("platformVersion", "4.4");
caps.setCapability("platformName","Android");
caps.setCapability("app","sauce-storage:HelloGappium-android.zip");
driver = new AndroidDriver<>(new URL(URL), caps);
return driver;
}
Please let me know if I am missing anything as I am new to sauce labs
Please share your working caps for sauce labs specific to android
Here you can find the platform configurator. Sauce Labs supply it to help with getting the right caps which is what you need. Based on your configuration, the correct caps will look like this for web testing:
DesiredCapabilities caps = DesiredCapabilities.android();
caps.setCapability("appiumVersion", "1.6.4");
caps.setCapability("deviceName","Android Emulator");
caps.setCapability("deviceOrientation", "portrait");
caps.setCapability("browserName", "Browser");
caps.setCapability("platformVersion", "4.4");
caps.setCapability("platformName","Android");
for Hybrid or App testing, the browserName will be set as:
caps.setCapability("browserName", "");
I'm a newbie with Selenium WebDriver. I found some sample code, and adapted it a little bit to get my own test program. I'm having trouble with it! Here's the program:
package test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class SeleniumTester {
public static void main(String[] args) {
try {
System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\Selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.oddsportal.com/");
driver.manage().window().maximize();
String str = driver.getCurrentUrl();
System.out.println("The current URL is " + str);
}
catch (Exception ex) {
System.out.println("Encountered exception in SeleniumTester.main() :");
System.out.println(ex.getMessage());
}
}
}
It compiles fine, and starts running, first outputting some diagnostics:
"Starting ChromeDriver (v2.9.248315) on port 11716
October 25, 2017 6:11:22 IP.
org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS"
But then, at the line "driver.get(...);" an exception occurs :
"Encountered exception in SeleniumTester.main() :
unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"8164.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:40.131Z'
System info: host: 'DESKTOP-47EFBCO', ip: '192.168.43.83', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, chrome={userDataDir=C:\Users\Ilkka\AppData\Local\Temp\scoped_dir12200_17489}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=61.0.3163.100, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, platformName=XP, cssSelectorsEnabled=true}]
Session ID: 31a4a5806225e18533805ed0fbbca392"
Something about invalid context. What does it mean? How to fix it? Should I perhaps use a different constructor to create the ChromeDriver? Ideas, anyone?
Most likely the issue is because of an older version of chromedriver. Download a newer version of chromedriver and try giving its path.
The browser version and driver version compatibility issues could cause this issue. The chromedriver page mentions the driver compatibility for browser version. For example, as of now, the page lists:
Latest Release: ChromeDriver 2.33
Supports Chrome v60-62
I am fairly new to selenium and trying to invoke the Firefox browser using the following java code.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class google {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver", "/Users/gowtham/Desktop/Selenium/geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("http://google.com");
Thread.sleep(1000);
driver.quit();
}
}
When I run the above code, I get the following exception on my console.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, browserName=firefox, moz:firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions#7d70d1b1, version=, platform=ANY, firefox_profile=org.openqa.selenium.firefox.FirefoxProfile#2a742aa2}], required capabilities = Capabilities [{}]
Build info: version: 'unknown', revision: '86a5d70', time: '2017-02-16 07:47:51 -0800'
System info: host: 'system', ip: 'fe80:0:0:0:2acf:e9ff:fe19:261%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_45'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:293)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:272)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:267)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:263)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:122)
at HelloWorls.google.main(google.java:11)
I have firefox v52.0 installed on my machine.
Please share your thoughts on this issue.
I can't add comments so far, so post the way to resolve this problem here.
Indeed, gecko driver version needs to be downgraded.
For those, who are using 'bonigarcia-webdrivermanager', add driver version explicitly before instantiating FirefoxDriver:
FirefoxDriverManager.getInstance().setup("0.14.0");
I am using Firefox 47.0.1 with Marionette driver geckodriver-v0.8.0-win32. But I got unreachable browser exception and firefox not opening.
My code snippet looks like below :
System.setProperty("webdriver.gecko.driver", "C:/Documents and Settings/Admin/Desktop/wires-0.6.2-win/wires.exe");
GeckoDriverService service = new GeckoDriverService(new File("C:/Documents and Settings/Admin/Desktop/wires-0.6.2-win/wires.exe"), PortProber.findFreePort(), null, null);
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability("marionette", true);
cap.setCapability("firefox_binary", "G:/Program Files/Mozilla Firefox/firefox.exe");
driver = new MarionetteDriver(service, cap,PortProber.findFreePort());
showing exception as :-
org.openqa.selenium.remote.UnreachableBrowserException: Could not
start a new session. Possible causes are invalid address of the remote
server or browser start-up failure.
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'computer_1', ip: '192.168.1.100', os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version:
'1.7.0_79'
Driver info: driver.version: MarionetteDriver
There is no need for renaming geckodriver.exe to wires.exe. And usage of GeckoDriverService is not needed. With the stable release they've simplified the coding. Just download GeckoDriver and use it like
System.setProperty("webdriver.gecko.driver", "path\\to\\geckodriver.exe");
DesiredCapabilities caps = DesiredCapabilities.firefox();
caps.setCapability(FirefoxDriver.BINARY, "G:\\Program Files\\Mozilla Firefox\\firefox.exe");
WebDriver driver = new MarionetteDriver(caps);
I'm assuming, you are using selenium 3.0 beta2. Here is the solution:
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe"); //change geckodriver path accordingly.
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
webDriver = new MarionetteDriver(capabilities);
Please download latest geckodriver from https://github.com/mozilla/geckodriver/releases.