org.openqa.selenium.InvalidSelectorException: Unsupported CSS selector error when using #AndroidFindBy(uiAutomator = - scroll

I am trying to automate a scenario in an android application using appium, java. I need to scroll down to an element on the screen to enter a text value. I'm initializing the elements using page factory as shown below.
#AndroidFindBy(uiAutomator = "new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().resourceId(\"com.call4site.handymanservices:id/email\"))")
private WebElement txt_email;
I'm getting a strange error in console as below.
org.openqa.selenium.InvalidSelectorException:
Unsupported CSS selector '*[name='txt_email']'. Reason: 'Error: 'name' is not a valid attribute. Supported attributes are 'checkable, checked, clickable, enabled, focusable, focused, long-clickable, scrollable, selected, index, instance, description, resource-id, text, class-name, package-name''
For documentation on this error, please visit: https://selenium.dev/exceptions/#invalid_selector_exception
Build info: version: '4.6.0', revision: '79f1c02ae20'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11'
Driver info: io.appium.java_client.android.AndroidDriver
Command: [da3c259c-cf9d-4457-967a-060eadf5f643, findElement {using=css selector, value=*[name='txt_email']}]
Capabilities {appium:app: C:\Users\laksh\Downloads\ha..., appium:appPackage: com.call4site.handymanservices, appium:automationName: uiautomator2, appium:databaseEnabled: false, appium:
desired: {app: C:\Users\laksh\Downloads\ha..., automationName: uiautomator2, deviceName: Android Emulator, platformName: android, platformVersion: 11.0, udid: emulator-5554}, appium:de
viceApiLevel: 30, appium:deviceManufacturer: unknown, appium:deviceModel: Android SDK built for x86, appium:deviceName: emulator-5554, appium:deviceScreenDensity: 560, appium:deviceScr
eenSize: 1440x2560, appium:deviceUDID: emulator-5554, appium:javascriptEnabled: true, appium:locationContextEnabled: false, appium:networkConnectionEnabled: true, appium:pixelRatio: 3.
5, appium:platformVersion: 11, appium:statBarHeight: 84, appium:takesScreenshot: true, appium:udid: emulator-5554, appium:viewportRect: {height: 2308, left: 0, top: 84, width: 1440}, appium:warnings: {}, appium:webStorageEnabled: false, platformName: ANDROID}
Session ID: da3c259c-cf9d-4457-967a-060eadf5f643
at tests.signUpTests.signUpAsNewUser(signUpTests.java:32)
But if I use the following code to initialize the element, then I'm able to scroll down and enter text to it. Has anyone faced this issue?
WebElement txt_email = driver.findElement(AppiumBy.androidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().resourceId(\"com.call4site.handymanservices:id/email\"))"));

Related

My WebDriver automatically closes after test, without any methods (tearDown).I am using Spring Boot + Selenium

When I start test It is Okay, but when The test is finished, WebDriver just closes. I am not using tearDown method.Tests are finished succesful, but when I wanted to create #PreDestroy, I got a mistake:
2022-08-18 17:56:17.822 WARN 476 --- [ main]
.s.c.a.CommonAnnotationBeanPostProcessor : Destroy method on bean with name 'homePage' threw
an exception: org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver
after calling quit()?
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'DESKTOP-93EP0G1', ip: '192.168.0.103', os.name: 'Windows 10', os.arch:
'amd64', os.version: '10.0', java.version: '18.0.1.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, getTitle {}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 103.0.5060.114,
chrome: {chromedriverVersion: 103.0.5060.134 (8ec6fce403b..., userDataDir:
C:\Users\alexe\AppData\Loca...}, goog:chromeOptions: {debuggerAddress: localhost:52653},
javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform:
WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://localhost:52653/devtoo...,
se:cdpVersion: 103.0.5060.114, setWindowRect: true, strictFileInteractability: false, t
imeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and
notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true,
webauthn:virtualAuthenticators: true
My config:
#Configuration
public class WebDriverConfig {
#Bean
#ConditionalOnMissingBean
#ConditionalOnProperty(name = "browser", havingValue = "chrome")
#Primary
public WebDriver chromeDriver() {
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
return driver;
}

WebDriver wait command is failing for Safari on Mac OS

I have script to login to a site and then waiting for home button to get loaded. I have put fluentwait to wait for element to be visible. But WebDriver is not waiting and failing immediately as the home button is not loaded.
I have tried with fluentwait and webdriverwait but none of them are working.
Here is code I am trying.
By usernameInput = By.name("User”);
By passwordInput = By.name("Password”);
By loginButton = By.xpath("//input[#value='Sign In']”);
String URL = “https://demotest.mytest.com/"
WebDriver driver = new SafariDriver();
driver.get(URL);
driver.manage().window().maximize();
setText(usernameInput,”User1");
setText(passwordInput,”User1");
clickOnElement(loginButton);
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[#title='Home']")));
Throws below error -
org.openqa.selenium.WebDriverException:
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'cnparmar-mac', ip: '10.168.104.60', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.6', java.version: '1.8.0_211'
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities {acceptInsecureCerts: false, browserName: Safari, browserVersion: 12.1.1, javascriptEnabled: true, platform: MAC, platformName: MAC, safari:automaticInspection: false, safari:automaticProfiling: false, safari:diagnose: false, setWindowRect: true, strictFileInteractability: false, webkit:WebRTC: {DisableICECandidateFiltering: false, DisableInsecureMediaCapture: false}}
Session ID: 1257BF8B-335E-4E80-8B08-CB15A77AD648
*** Element info: {Using=xpath, value=//div[#title='Home']}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructo rAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingCo nstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException( W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpRes ponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpRes ponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExec utor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(Drive rCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.jav a:552)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver .java:323)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWe bDriver.java:428)
at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver .java:315)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedCond itions.java:205)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedCond itions.java:201)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:249)
at sample.Sample.loginAs(Sample.java:64)
at sample.Sample.test1(Sample.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j ava:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess orImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocati onHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorke r.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
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)
Ideally it should wait for Home button to get visible. but it is failing. This works on Chrome,Firefox, IE, Edge on Windows but only failing on Safari on MAC.
It looks like you are mixing up WebDriverWait and FluentWait classes.
Try using the following instead:
WebDriverWait wait = new WebDriverWait(driver, 15, 100);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[#title='Home']")));

Time out exception is displaying while running "Protractor test script" in "internet explorer" browser

I am unable to run "protractor test script" in "Internet explorer" browser.
I run below command.
webdriver-manager update --ie --versions.standalone 3.4.0 --versions.ie 3.4.0
my configuration file code is as below.
exports.config = {
allScriptsTimeout: 15000,
seleniumAddress:'http://localhost:4444/wd/hub',
capabilities:
{
'browserName': 'internet explorer',
'platform' : 'ANY',
'version' : '11'
},
suites: {
heropage: ['e2e/hero/hero.e2e-spec.ts'],
dashboardpage : ['e2e/dashboard/dashboard.e2e-spec.ts']
},
baseUrl: 'http://localhost:4200/',
// directConnect : true,
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 50000,
includeStackTrace: true
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
},
}
I change all the required setting for internet explorer browser in "internet options" by following http://elgalu.github.io/2014/run-protractor-against-internet-explorer-vm/
I am getting below error
Failed: JavaScript error in async script. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 26 milliseconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'BHUVISDESK-16', ip: '192.168.0.109', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0',
java.version: '1.8.0_144'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{se:ieOptions={browserAttachTimeout=0.0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, i
e.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000.0,
ie.useLegacyFileUploadDialogHandling=false, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0.0, ie.
browserCommandLineSwitches=, requireWindowFocus=false, initialBrowserUrl=http://localhost:39545/, ignoreProtectedModeSetti
ngs=false, enableElementCacheCleanup=true}, browserName=internet explorer, pageLoadStrategy=normal, javascriptEnabled=true
, version=11, platform=WINDOWS, unexpectedAlertBehaviour=dismiss}]
Session ID: 01bf3915-d549-421b-a6f1-771e17c78cc7
Can any one help me what's my mistake in this process

Run my Selenium Scripts to test the Web page which is connected via Remote Desktop Connection?

I want to test the Web Pages which is connected through RDC and that web pages can't access from my machine browser, it can be accessed only through RDC.
I wrote my scripts to open the chrome browser on my local machine,
System.setProperty("webdriver.chrome.driver", "C:\selenium-java-
3.1.0\chromedriver_win32\chromedriver.exe");
driver = new ChromeDriver();
How can i write the selenium scripts to connect the browser which is from RDC.
Please someone help me to do this.
This is what it showing me in commandLine
18:29:15.105 INFO - Executing: [new session: Capabilities [{marionette=true, browserName=firefox, version=, platform=WINDOWS}]])
18:29:15.111 INFO - Creating a new session for Capabilities
[{marionette=true, browserName=firefox, version=, platform=WINDOWS}]
18:29:15.119 WARN - Exception thrown
java.util.concurrent.ExecutionException:
org.openqa.selenium.WebDriverException:
java.lang.reflect.InvocationTargetException Build info: version:
'3.4.0', revision: 'unknown', time: 'unknown' System info: host:
'DESKTOP-U53JQ9J', ip: '10.2.50.41', os.name: 'Windows 10', os.arch:
'amd64', os.version: '10.0', java.version: '1.8.0_111' Driver info:
driver.version: unknown
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:183)
at org.openqa.selenium.remote.server.DefaultSession.(DefaultSession.java:119)
at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:95)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException Build info: version:
'3.4.0', revision: 'unknown', time: 'unknown' System info: host:
'DESKTOP-U53JQ9J', ip: '10.2.50.41', os.name: 'Windows 10', os.arch:
'amd64', os.version: '10.0', java.version: '1.8.0_111' Driver info:
driver.version: unknown
at org.openqa.selenium.remote.server.FirefoxDriverProvider.callConstructor(FirefoxDriverProvider.java:89)
at org.openqa.selenium.remote.server.FirefoxDriverProvider.newInstance(FirefoxDriverProvider.java:63)
... 1 more Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Caused by: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property;
for more information, see https://github.com/mozilla/geckodriver. The
latest version can be downloaded from
https://github.com/mozilla/geckodriver/releases
at com.google.common.base.Preconditions.checkState(Preconditions.java:738)
18:29:15.374 WARN - Exception: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more
information, see https://github.com/mozilla/geckodriver. The latest
version can be downloaded from
https://github.com/mozilla/geckodriver/releases 18:29:15.416 INFO -
Executing: [new session: Capabilities [{marionette=true,
browserName=firefox, version=, platform=WINDOWS}]]) 18:29:15.420 INFO
- Creating a new session for Capabilities [{marionette=true, browserName=firefox, version=, platform=WINDOWS}] 18:29:15.430 WARN -
Exception thrown java.util.concurrent.ExecutionException:
org.openqa.selenium.WebDriverException:
java.lang.reflect.InvocationTargetException Build info: version:
'3.4.0', revision: 'unknown', time: 'unknown' System info: host:
'DESKTOP-U53JQ9J', ip: '10.2.50.41', os.name: 'Windows 10', os.arch:
'amd64', os.version: '10.0', java.version: '1.8.0_111' Driver info:
driver.version: unknown
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException Build info: version:
'3.4.0', revision: 'unknown', time: 'unknown' System info: host:
'DESKTOP-U53JQ9J', ip: '10.2.50.41', os.name: 'Windows 10', os.arch:
'amd64', os.version: '10.0', java.version: '1.8.0_111' Driver info:
driver.version: unknown
at org.openqa.selenium.remote.server.FirefoxDriverProvider.callConstructor(FirefoxDriverProvider.java:89)
at org.openqa.selenium.remote.server.FirefoxDriverProvider.newInstance(FirefoxDriverProvider.java:63)
18:29:15.639 WARN - Exception: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more
information, see https://github.com/mozilla/geckodriver. The latest
version can be downloaded from
https://github.com/mozilla/geckodriver/releases 18:29:15.676 WARN -
Exception thrown java.lang.NullPointerException
at java.util.HashMap.putMapEntries(Unknown Source)
at java.util.HashMap.putAll(Unknown Source)
18:29:15.749 WARN - Exception: null java.lang.IllegalStateException:
The path to the driver executable must be set by the
webdriver.gecko.driver system property; for more information, see
https://github.com/mozilla/geckodriver. The latest version can be
downloaded from https://github.com/mozilla/geckodriver/releases
This is my code in eclipse
public void setup() throws Throwable {
// System.setProperty("webdriver.gecko.driver","C:\selenium-java-3.1.0\geckodriver-v0.14.0-win64\geckodriver.exe");
File file = new
File("C:\selenium-java-3.1.0\geckodriver-v0.14.0-win64\geckodriver.exe");
System.setProperty("webdriver.gecko.driver",
file.getAbsolutePath());
DesiredCapabilities cap=DesiredCapabilities.firefox(); cap.setPlatform(Platform.WINDOWS); cap.setBrowserName("firefox");
URL url=new URL("http://192.168.2.98:4444/wd/hub"); WebDriver
driver=new RemoteWebDriver(url, cap);
driver.get("http://learn-automation.com/");
It sounds like you want to execute the tests on a remote machine. you can make this possible via Selenium Grid Server.
With Selenium Grid Server you can set up a node on you remote pc and let that node open a browser.
This node is connected to a hub, the hub will receive the commands and sent them to the node.
Is this what you are looking for?
An example configuration for a hub:
java -jar selenium-server-standalone-<version>.jar -role hub -hubConfig hubConfig.json
Contents of hubConfig.json
{
"_comment" : "Configuration for Hub - hubConfig.json",
"host": ip,
"maxSessions": 5,
"port": 4444,
"cleanupCycle": 5000,
"timeout": 300000,
"newSessionWaitTimeout": -1,
"servlets": [],
"prioritizer": null,
"capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
"throwOnCapabilityNotPresent": true,
"nodePolling": 180000,
"platform": "WINDOWS"
}
An example configuration for a node:
java -jar selenium-server-standalone-<version>.jar -role node -nodeConfig nodeConfig.json
Contents of nodeConfig.json
{
"capabilities":
[
{
"browserName": "opera",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver",
"webdriver.opera.driver": "C:/Selenium/drivers/operadriver.exe",
"binary":"C:/Program Files/Opera/44.0.2510.1159/opera.exe"
},
{
"browserName": "chrome",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver",
"webdriver.chrome.driver": "C:/Selenium/drivers/chromedriver.exe",
"binary":"C:/Program Files/Google/Chrome/Application/chrome.exe"
},
{
"browserName": "firefox",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver",
"webdriver.gecko.driver": "C:/Selenium/drivers/geckodriver.exe",
"binary":"C:/Program Files/Mozilla Firefox/firefox.exe"
}
],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hub": "http://localhost:4444",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {}
}
Drivers downloads
Place all the drivers in your path variable
Chrome driver
FireFox driver
Microsoft Edge driver
Opera driver
Browsers downloads
Chrome
FireFox
Microsoft Edge
Opera
Selenium cannot connect to the remote server through RDP.
You'll need to set up VPN connection between services or something like ngrok

How can I use HTML xpath while automating iPhone application

Im using Appuim+ Selenium Webdriver.
My App is build in Sencha FrameWork so that some of the elements can not be found using Appium Inspector.
So I tried with HTML Xpath, but it gives "element not found exception".
Im pasting the code below:
wd.findElement(By.xpath("//*[#id='DashBoardView_cityInsightsItemId']/div/div/div[2]/div[1]/div")).click();
Err in Console is:
*exceptionorg.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: 1.52 seconds For documentation on this
error, please visit:
http://seleniumhq.org/exceptions/no_such_element.html Build info:
version: '2.51.0', revision: '1af067d', time: '2016-02-05 19:15:17'
os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5',
java.version: '1.8.0_73' Driver info:
org.openqa.selenium.remote.RemoteWebDriver Capabilities [] Session
ID: 4c466315-67c5-409e-9ffc-1f0d26c134c4
Element info: {Using=xpath, value=//[#id='DashBoardView_cityInsightsItemId']/div/div/div[2]/div[1]/div}*
HTML Code:
<div class="x-container dashboard_item_cls x-layout-box-item x-stretched" id="DashBoardView_cityInsightsItemId" style=""><div class="x-inner x-vertical x-align-center x-pack-center x-layout-box" id="ext-element-125"><div class="x-img x-img-image x-paint-monitored x-size-monitored dashboard_icon_cls cityInsights_icon_cls x-img-background x-layout-box-item x-stretched" id="ext-image-3"><div class="x-paint-monitor cssanimation"></div><div class="x-size-monitors overflowchanged"><div class="expand"><div style="width: 68.1875px; height: 68.1875px;"></div></div><div class="shrink"><div style="width:
67.1875px; height: 67.1875px;"></div></div></div></div></div></div>
I want to find this element:
<div style="width: 68.1875px; height: 68.1875px;"></div>
Why do I get this error and how do I solve it?

Resources