FluentWait not ignoring exceptions [duplicate] - selenium

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)

Related

Selenium 4.x trying to POST CDP: "UnsupportedCommandException"

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...."
}
}

Selenium IDE tests failing when run on Selenium Grid

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.

selenium find element by id with firefox failed

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 ?

Events received by client websocket as a consequence of calling builder.Prompts.text() in a bot are missing the activity payload

botframework Node.js [DirectLine 3.0 API / React Native Client (Android)] Events received by client websocket as a consequence of calling builder.Prompts.text() in a bot are missing the ‘data’ property (i.e. the activity payload).
Version Information
React Native Client (Android)
Node.js v7.5.0
react-native v0.41.2
Bot
Node.js v6.3.1
botbuilder v3.7.0
DirectLine
API v3.0
Description of Issue
Events received by client websocket as a consequence of calling builder.Prompts.text() in a bot are missing the ‘data’ property (i.e. the activity payload).
Note: Subsequent events following this one will include the Symbol ‘original_event’ which includes the missing event details that would have been expected in the initial event.
Direct Line request from bot (i.e. captured from ChatConnector.authenticatedRequest()):
{
json: true,
method: “POST”,
url: “https://state.botframework.com/v3/botstate/directline/conversations/[MY CONVERSATION ID]”,
body: {
from: {
id: “MyBot#ZSXyfFggVqW”,
name: “MyBot”
},
recipient: {
id: “MyClientId”
},
text: “Hi Pete, please enter the code displayed in the browser page to complete the sign in process.”,
type: “message”
}
}
Event received by websocket:
{
… // Expecting a data property at this level. Don’t confuse this with the data property in the Symbol below, which is for the previous event.
Symbol(original_event): {
data: "{
"activities": [
{
"type": "typing",
"id": "[MY CONVERSATION ID]|5ChLjtMKBEz",
"timestamp": "2017-05-04T10:37:48.3923201Z",
"channelId": "directline",
"from": {
"id": "MyBot",
"name": "MyBot"
},
"conversation": {
"id": "[MY CONVERSATION ID]"
}
}
]}",
type: ”message”
},
timestamp: 1493894269211,
type: “message”
}
Event after the one above contains:
{
…
Symbol(original_event): {
data: "{
"activities": [
{
"type": "message",
"id": "[MY CONVERSATION ID]|0000030",
"timestamp": "2017-05-04T10:37:49.092354Z",
"channelId": "directline",
"from": {
"id": "MyBot",
"name": "MyBot"
},
"conversation": {
"id": "[MY CONVERSATION ID]"
},
"text": "Hi Pete, please enter the code displayed in the browser page to complete the sign in process.”
}
],
"watermark": "30"
}",
type: ”message”
},
timestamp: 1493894511787,
type: “message”
}
Notes:
• Notice that the event following the original has the data property we would have expected, contained in the Symbol “original_event”.
• If the same conversation thread is attempted for any other channel type, the message “Hi Pete, please enter the code displayed in the browser page to complete the sign in process” IS shown in the chat window (i.e. Skype, Slack, Web Chat etc). It is only direct line that appears to have the issue.
• The message in question is a proactive message triggered after a user has been authenticated and a redirect URL called. The message is required to prompt the user for a second form of authentication, in this particular case an access code.
• If all historic message activities are requested for the above conversation, the missing message is among said activities i.e.:
https://directline.botframework.com/v3/directline/conversations/[MY CONVERSATION ID]/activities?watermark=[INITIAL WATERMARK]
{
"activities": [
…
{
"type": "message",
"id": "[MY CONVERSATION ID]|0000009",
"timestamp": "2017-05-04T17:48:33.0747342Z",
"channelId": "directline",
"from": {
"id": "MyBot"
},
"conversation": {
"id": "[MY CONVERSATION ID]"
},
"text": "Hi Pete, please enter the code displayed in the browser page to complete the sign in process."
}
…
Any suggestions?
Update 05/05/2017
Currently pursing two avenues of thought, either there is an issue with the WebSocket library bundled with React Native, or we have a general Direct Line WebSocket issue (a colleague of mine will be retesting with a native IOS client this morning to confirm one way or another).
No longer an issue. Websocket events now appear to be coming through as expected.

Taking screenshots with Selenium Builder

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.