I'm using Windows MobaXTerm for execute command. i execute Selenium by this command :
cd /drives/c/selenium; java -Dhttp.proxyHost=http://proxy.wideip -Dhttp.proxyPort=3128 -Dwebdriver.gecko.driver="C:\selenium\geckodriver.exe" -jar selenium-server-standalone-3.8.1.jar -port 4444
My geckodriver is into version 0.20 (the last actualy) My selenium version is greater then 3 and in fact include marionette.
For try to identify my problem i'm using postman.
Step 1 : Create session
Step 2 : set Url
Step 3 : get element by id
In step get element by id i have this result (in chrome)
{
"sessionId": "448e264843b4bbf506f03491b2bf940d",
"status": 0,
"value": {
"ELEMENT": "0.28994850647447534-1"
}
}
and this result in firefox :
{
"state": "success",
"sessionId": null,
"hCode": 23764448,
"value": {
"element-6066-11e4-a52e-4f735466cecf": "17752648-8258-4338-8a0e-40be95c874c4"
},
"class": "org.openqa.selenium.remote.Response",
"status": 0
}
For query i'm using same :
http://localhost:4444/wd/hub/session/{{selenium_session_id}}/element
and for query body i'm sending same :
{"using":"id","value":"id_button_submit"}
Of course i'm using same url / and same try.
But in FF i'm don't have result.value.ELEMENT, and if i don't have it, i can't have driverElementId, and click into, all my try's scenario is failed for FF
I'm using last Developer FF version.
May you give me idea for identify my problem and solve it please ?
Related
I`m trying to execute some commands via CDP, however no matter what combination of Selenium/Driver/Chrome I use it's always the same result.
Last tested with:
Selenium 4.1.1
Chrome + Driver 96.0.4664.110
The project is made in C so I am posting manually to Selenium via CURL. Every other command besides CDP works fine.
I have checked Selenium, Chrome Driver; they both have the CDP support built in.
The URL's I tried to post to are:
- /session/id/goog/cdp/execute
- /session/id/{}/cdp/execute
The posted data format is: "cmd" + "params" (json object).
Both end in the same result: org.openqa.selenium.UnsupportedCommandException.
I also tried to run Selenium in different modes, standalone, hub/node, same result.
Can someone please advise what I am doing wrong? Or maybe I have misunderstood the usage?
Using chromedriver executable
This worked for me (Windows + Postman), but should also work with CURL Linux/Mac.
1 Download chromedriver: https://chromedriver.chromium.org/downloads for your chrome version.
2 Start chromedriver
start chromedriver.exe
output:
Starting ChromeDriver 97.0.4692.71 on port 9515...
3 Send requests to localhost:9515/
3.1 Create Session:
POST localhost:9515/session
request json body:
{"capabilities":{"goog:chromeOptions": {}}}
status 200
response:
"value": {
"capabilities": {
...
},
"sessionId": "b8ac49ce2203739fa0d32dfe8d1a23b5"
3.2 Navigate some url (optional, just check request by sessionId works):
POST localhost:9515/session/b8ac49ce2203739fa0d32dfe8d1a23b5/url
request json body:
{"url": "https://example.com"}
status 200
3.3 Execute CDP command (take screenshot):
POST localhost:9515/session/b8ac49ce2203739fa0d32dfe8d1a23b5/goog/cdp/execute
request json body:
{"cmd":"Page.captureScreenshot", "params":{}}
status 200
response:
{
"value": {
"data": "iVBORw0KGgoAAAANSUhEUgA...."
}
}
Allow remote connections
By default chromedriver allows only local connections.
To allow some remote IPs:
start chromedriver.exe --allowed-ips="some-remote-ip"
Reference: https://sites.google.com/a/chromium.org/chromedriver/security-considerations
Run CDP commands with Selenium Grid
Eventually, it started to work for me with
ChromeDriver 97.0.4692.71
selenium-server-4.1.1
Chrome 97.0.4692.71 (Official Build) (64-bit)
Note: Content-Type header should have charset=utf-8
Content-Type:application/json;charset=utf-8 for Selenium Grid HTTP requests.
Prerequisites
1 Download and run selenium server according to
https://www.selenium.dev/documentation/grid/getting_started/
java -jar selenium-server-<version>.jar standalone --driver-configuration display-name='Chrome' stereotype='{"browserName":"chrome"}'
2 Create Session:
POST localhost:4444/wd/hub/session
request json body:
{
"desiredCapabilities": {
"browserName": "chrome",
"goog:chromeOptions": {
"args": [
],
"extensions": [
]
}
},
"capabilities": {
"firstMatch": [
{
"browserName": "chrome",
"goog:chromeOptions": {
"args": [
],
"extensions": [
]
}
}
]
}
}
status 200
response:
{
"status": 0,
"sessionId": "69ac1c82306f72c7aaf53cfbb28a30e7",
...
}
}
3 Execute CDP command (take screenshot):
POST localhost:4444/wd/hub/session/69ac1c82306f72c7aaf53cfbb28a30e7/goog/cdp/execute
request json body:
{"cmd":"Page.captureScreenshot", "params":{}}
status 200
response:
{
"value": {
"data": "iVBORw0KGgoAAAANSUhEUgA...."
}
}
I have a setup where I make simple tests with the Selenium IDE, then save the project as a *.side file to a repository, which a server running Selenium Grid then pulls, runs all tests contained and then emails me the results. For most of the tests I get the same results as locally, only a few cookie banners caused trouble because it seems that locally it's not an issue if you don't click them away but when the tests run on the Selenium Grid they will fail because the cookie banner blocks all clicks. Now I have a similar issue but there is nothing like a cookie banner. I am testing a Swagger UI and whenever I run the test on Selenium Grid I get failures like this:
FAIL DefaultSuite/click-a-couple-headers.test.js (7.275s)
✕ click-a-couple-headers (5319ms)
● click-a-couple-headers
ElementClickInterceptedError: element click intercepted: Element <div class="opblock-summary opblock-summary-get">...</div> is not clickable at point (476, 18). Other element would receive the click: <header>...</header>
(Session info: chrome=80.0.3987.106)
at Object.throwDecodedError (../../../node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (../../../node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/http.js:560:13)
at Executor.execute (../../../node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/http.js:486:26)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 7.58s, estimated 8s
Searching for the CSS selector in the Selenium IDE test this seems to be the part where it fails:
{
"id": "12345678-1111-5555-8888-1234567890ab",
"comment": "",
"command": "setWindowSize",
"target": "968x648",
"targets": [],
"value": ""
}, {
"id": "12345678-2222-6666-8888-1234567890ab",
"comment": "",
"command": "runScript",
"target": "window.scrollTo(0,413)",
"targets": [],
"value": ""
}, {
"id": "12345678-4444-7777-8888-1234567890ab",
"comment": "",
"command": "click",
"target": "css=#operations-category-method_path_to_endpoint > .opblock-summary",
"targets": [
["css=#operations-category-method_path_to_endpoint > .opblock-summary", "css:finder"],
["xpath=//div[#id='operations-category-method_path_to_endpoint']/div", "xpath:idRelative"],
["xpath=//span[2]/div/div/span/div/div", "xpath:position"]
],
"value": ""
}
So I thought it might be a timing issue with the scrolling operation, so I added a whatForElementVisible command before all clicks:
/* scroll command */
{
"id": "12345678-3333-7777-8888-1234567890ab",
"comment": "",
"command": "waitForElementVisible",
"target": "css=#operations-category-method_path_to_endpoint > .opblock-summary",
"targets": [
["css=#operations-category-method_path_to_endpoint > .opblock-summary", "css:finder"],
["xpath=//div[#id='operations-category-method_path_to_endpoint']/div", "xpath:idRelative"],
["xpath=//span[2]/div/div/span/div/div", "xpath:position"]
],
"value": "30000"
},
/* click command */
Locally the test still worked fine in Firefox and Chrome (which the Grid runs) but on the Grid it fails with the same error as before. Does someone know how to fix this issue or how to properly debug it?
Turns out it wasn't an issue with timing at all, but rather a problem with an information bar (about the browser being controlled with automation software) at the top of the browser window that I didn't get locally. The video recording feature of Selenium Grid Extras proved to be really useful to track this down. Useful to know because the README of the repo doesn't mention it: the node info (and videos) are exposed on the ports 3100 (Chrome browser) and 3200 (FireFox browser) respectively.
This question already has answers here:
NoSuchElementException, Selenium unable to locate element
(3 answers)
The type FluentWait is not generic; it cannot be parameterized with arguments <WebDriver> error for FluentWait Class through Selenium and Java
(6 answers)
Closed 3 years ago.
I have some Selenium Chromedriver code that is clicking on a button, then several seconds later an item appears on the web page that I need to capture the text (basically a success/fail response). I can see the button click is working, but the script stops with an exception almost immediately after the button is pressed. I can verify the button click has worked because a few seconds after the script has stopped, the element to be checked appears on screen.
The exception is;
Caused by org.openqa.selenium.NoSuchElementException: no such element
This makes sense because at the time this exception occurs the element is not there, and it won't be there for several seconds.
The exception comes from this command;
myWaitVar.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[#data-aura-class=\"forceActionsText\"]")));
With myWaitVar defined as;
myWaitVar = new FluentWait<WebDriver>(driver)
.withTimeout(Duration.ofSeconds(120))
.pollingEvery(Duration.ofSeconds(10))
.ignoring(org.openqa.selenium.NoSuchElementException.class);
The ignoring command was changed from NoSuchElementException.class because I saw another Stackoverflow response saying that it has to be the org.openqa.selenium version.
From what I understand, the line should wait for up to 120 seconds, checking every 10 seconds for the element to appear. However, the test result shows that it completes in 0.076 seconds.
I would be happy if I had got the xpath wrong and it actually took 120 seconds to break. But with it breaking in just over a second I believe the issue could be somewhere else.
Edit: The element is identified correctly if I add a thread sleep of exactly 7 seconds. With a 7 second delay, the element appears on screen, the fluentwait passes and so does the rest of the test. This suggests that the element locator is accurate, there is no iframe to navigate, no other DOM setting that prevents the locator from working at the right time. I have also tried 'presence of' as well as 'visibility of' with the same result (I can't try 'is clickable' as it's just a text field and not clickable).
Edit 2: This is the debugging response for this request.
[1567065113.459][INFO]: [ebbf7271cafbc1f7e2dba437ac32b004] COMMAND FindElement {
"using": "xpath",
"value": "//*[#data-aura-class=\"forceActionsText\"]"
}
[1567065113.459][INFO]: Waiting for pending navigations...
[1567065113.459][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=246) CB6F87B5FC515B000A21C08C843E210B {
"expression": "1"
}
[1567065113.464][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=246) CB6F87B5FC515B000A21C08C843E210B {
"result": {
"description": "1",
"type": "number",
"value": 1
}
}
[1567065113.464][INFO]: Done waiting for pending navigations. Status: ok
[1567065113.467][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=247) CB6F87B5FC515B000A21C08C843E210B {
"expression": "(function() { // Copyright (c) 2012 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\n/**\n * Enum f...",
"returnByValue": true
}
[1567065113.481][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=247) CB6F87B5FC515B000A21C08C843E210B {
"result": {
"type": "object",
"value": {
"status": 0,
"value": null
}
}
}
[1567065113.481][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=248) CB6F87B5FC515B000A21C08C843E210B {
"expression": "1"
}
[1567065113.483][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=248) CB6F87B5FC515B000A21C08C843E210B {
"result": {
"description": "1",
"type": "number",
"value": 1
}
}
[1567065113.483][INFO]: Waiting for pending navigations...
[1567065113.483][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=249) CB6F87B5FC515B000A21C08C843E210B {
"expression": "1"
}
[1567065113.483][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=249) CB6F87B5FC515B000A21C08C843E210B {
"result": {
"description": "1",
"type": "number",
"value": 1
}
}
[1567065113.483][INFO]: Done waiting for pending navigations. Status: ok
[1567065113.483][INFO]: [ebbf7271cafbc1f7e2dba437ac32b004] RESPONSE FindElement ERROR no such element: Unable to locate element: {"method":"xpath","selector":"//*[#data-aura-class="forceActionsText"]"}
(Session info: chrome=76.0.3809.132)
My fixtures are set up like so
{
"fixtures": [
{
"name": "login",
"pageUrl": "http:\/\/localhost:3000\/",
"tests": [
{
"name": "type name",
"commands": [
{
"type": "type-text",
"studio": {
},
"callsite": "0",
"selector": {
"type": "js-expr",
"value": "input[type=email]"
},
"options": {
},
"text": "example#email.com"
}
]
}
]
}
]
}
with one simple test to find the input and type some text but when running the command I get
testcafe chrome login.testcafe
ERROR Unable to establish one or more of the specified browser connections. This can be caused by network issues or remote device failure.
Type "testcafe -h" for help.
I've seen this issue a couple of times on their issues board one relating to CI integration on a Linux server and another which seems like a similar issue of trying to connect to localhost
https://github.com/DevExpress/testcafe-browser-provider-electron/issues/20
https://github.com/DevExpress/testcafe/issues/1133
New to testcafe any help would be appreciated!
I've found the solution some network policies don't allow access to your machine on some ports in my example it's 57501.
testcafe chrome login.testcafe --hostname localhost
adding --hostname resolves the issue
documentation
https://devexpress.github.io/testcafe/documentation/using-testcafe/command-line-interface.html#--hostname-name
I still don't know how to launch from the IDE but this resolves my main issue.
TestCafe Studio Preview does not support setting command line options (hostname in your case). The TestCafe team is going to implement this functionality in the official release.
So, for now, it is only possible to run tests via a command line.
UPDATE:
You can set the hostname option in the TestCafe Studio Settings dialog:
Using Selenium Builder, I've created the following json file:
{
"type": "script",
"seleniumVersion": "2",
"formatVersion": 2,
"steps": [
{
"type": "get",
"url": "http://stackoverflow.com/"
},
{
"type": "saveScreenshot",
"file": foo.png"
}
],
"data": {
"configs": {},
"source": "none"
},
"inputs": [],
"timeoutSeconds": 60
}
I tried running it on Windows 7 and two different Ubuntu machines. Instead of the filepath "foo.png" I had also inserted "E:\foo.png" / "/home/swege/foo.png". However, I always get the "exception":
Could not take screenshot of current page - [object Object]
At least I would like to be able to read the "error object", but every system just puts out that the error is a JavaScript object. Any idea how to fix the issue or read the full error message?
Try following :
http://www.ontestautomation.com/how-to-create-screenshots-in-your-selenium-webdriver-tests/
Above can help you to get exact code that how you can take screenshots using selenium.
So I pulled down and looked at the source for Selenium Builder 2 and found two files that I think show the origin of the error, command_processor.js and driver_component.js.
I can't make out why the error is occurring - maybe someone here can build on this?
Try using a full file path, not just foo.png. On Mac, these worked for me: ~/foo.png and ~/Downloads/screenshots/foo.png.
It's also important that the folder exists and is writable by the account running the web browser.