Require is not defined with selenium webdriver and broswersify does not appear to be not an option. How can I proceed? - selenium

My question relates to implementing the solution proposed in this post. The error I first get is that the webdriver is not defined. For that, I tried the following solution. But at that point, I get an error that "require()" is not defined, which brought me to this final solution. I tried the recommended Browserify option, but I don't think it's going to work for me because I can't just throw a "script src="bundle.js"" into the html as I want to use the webdriver to open the YouTube "stats for nerds" menu every time an ad is detected to get the video ID of that ad via a Chrome extension. Not sure if this is possible. Any help would be highly appreciated. I'm new to JS.

Related

How to enable Downloading PDF files through Karate ChromeDriver? [duplicate]

This question already has answers here:
API Automation Testing : Is there any way to automate download scenario with content validation?
(2 answers)
Closed 1 year ago.
When PDF hyperlinks selected using karate chromedriver, the files are opening in new tab rather than downloaded to the local system. I tried with below ChromeOptions while configuring the driver, but none of them looks worked for me.
karate.configure('driver;, {type:'chromedriver', executable: path, webDriverSession:{desiredCapabilities:{browserName:'chrome', "goog:chromeOptions":{"prefs": {"pdfjs.disabled": true}}}}});
Below preferences also did not work.
"prefs": {"plugins.always_open_pdf_externally": true,"plugins.plugins_disabled", "Chrome PDF Viewer"}
I went through karate docs but couldn't find a similar topic. I really appreciate if anyone can help me with this issue or guide me to the documentation.
Downloading files via WebDriver happens to be listed among their worst practices. The recommendation is to just get the URI from the DOM and use whatever http client you have available.
Thanks Peter & Matthias for the idea. I am able to download the file after updating the element DOM structure using JavaScript.
var lnkName = element.attribute['href'];
script("document.getElelmentById('pageLinks').setAttribute('download','"+lnkName+"');");
element.click();
I strongly suggest that in this case you just get the hyperlink of the PDF and use the Karate API testing functionality to download the file anywhere you want. You can find tips here: How to get the downloaded xlsx file from the api endpoint in karate? - and also look at the "upload.feature" example in the Karate demos.
If you need to execute some JS to get the final URL of the file, that is quite possible: https://stackoverflow.com/a/60800181/143475
Otherwise you need to continue doing some research, I don't know the answer and hopefully you can contribute your findings back.

Using Selenium to Retrieve data

I've been teaching myself Python and Selenium to automate a claim submission. I've managed to stumble through with lots searching and trial and error. However, I haven't been able to solve this last step. After the claim is submitted a claim number is generated:
<div class="zclip-target" id="claim-number">484508-638544</div>
I haven't been able to figure out how to retrieve this value. To no avail I tried:
claim_number=claim_number_element.getAttribute('value')
Any help or guidance would be appreciated.
P.S. there is also a button which copies that value to the clipboard. So if there is an easy way to grab the data from the clipboard that is another solution.
If you're working with python and selenium, it's a bit incorrect api for driver instance in selenium python library:
claim_number=claim_number_element.getAttribute('value')
try that:
claim_number=claim_number_element.get_attribute('value')
or
claim_number=claim_number_element.text

How can I trigger a click from the console with Cypress?

I'm trying to run commands on cypress from the command line. For instance, selecting an element and clicking on it.
I'm trying to do this to try some tests without having to need to run all the previous steps at this point. I'm not sure if this is possible due to the sequential nature of cypress, but it would be really helpful if there was some way to do it. I assumed something like this would be possible from the developer tools console:
cy.get('[data-test="save button"]').click()
I'm aware this doesn't work, so I tried with now and then and some other weird strategies. Reading the documentation didn't help. At least the part I read. Any details are appreciated.
--- edit ---
The console is on the same chrome instance that contains the selector playground like shown in in the image below.

Retrieve current chrome open page in html without saving it

I'm implementing a python script mainly based on pyautogui. One of the things the script does is to open a chrome webpage. After that I would need to access the DOM of this currently open webpage.
Since I've not opened the browser with selenium, I can't use it to analyze the DOM.
However, my question is: is this currently open chrome page available/saved somewhere in the hard drive so that I can access it with selenium? Like an .html file?
I checked many other questions here and users talk about chrome cache, but there are no html files there.
I just need to be able to access the current open page and not all the historical data in the cache.
Opening web browser directly with selenium is not an option either, since most of the websites analyzed have captchas and distil technology.
Thanks.
If you start the original chrome with --remote-debugging-port=PORT_NR argument, and visit localhost:PORT_NR from another browser, you will have access to the full content of the browser, including dev console.
Once you have this, you have multiple ways to go:
You can visit http://localhost:PORT_NR with with any other browser (or even with the same browser), and you should have full access to the content of the original Chrome. With Selenium you should have a relatively easy time to get by.
You can also use the devtools api (the documentation.. is.. well... there is room for improvement. Search for chrome devtools protocol to be amazed by the lack of docs). As an example you can get to http://localhost:PORT_NR/json to get the available debugging URIs. Grab the relevant websocket endpoint (webSocketDebuggerUrl). Open a websocket connection, and issue a command, like {"method": "DOM.getDocument", "id":12}. You can find available DOM related commands here: https://chromedevtools.github.io/devtools-protocol/1-3/DOM
Sice I had to reinvet the wheel I may give some extra info that I coudn't find anywhere:
Start the Browser with remote debugging enabled (see previous posts)
Connect to the given port on localhost and use these HTTP-GET-Requests to geta very limited control on your browser:
https://chromedevtools.github.io/devtools-protocol/#endpoints
Most important:
GET /json/new?{url}
GET /json/activate/{targetId}
GET /json/close/{targetId}
GET /json or /json/list
To gain full control over the browser, you need to use a "websocket" connection. Each Object in the GET /json or /json/list has it's own ID. Use this ID to interact with the tab. Btw: Type "page" are normal tabs, the other stuff are extentions and so on. Once you know which Tab you want to influence, get it's "webSocketDebuggerUrl".
Use this URL and connect with something that can speak the Websocket-protocol.
Once connected, you must craft a valid Json by the following structure:
{
"id":0,
"method":"Page.navigate",
"params":{url:http://google.com}}
}
Notes:
ID is a simple counter (int) that get bigger - not the ID of the tab(!)
Method is the method described in the docs params is also in the docs.
The return values are always JSONs.
From now on you can use the official docs:
https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-navigate
Dunno how other ppl found out about it but it took a few hours to get it working. Probably cause everyone is just using python's selenium to do it.

Selenium IDE issue on Mozilla firefox: table view is not available with this format

I am trying to work with the Selenium IDE on Mozilla Firefox (version 55.0.3).
The issue is that for some reason I cannot see any action I perform on the browser (such as waitForTitle, verify title etc.). They should be displayed in the Selenium IDE I have installed as a developer tool (in the table).
Also, when trying to click on something in the IDE, I get the following error message:
There was an unexpected error. Msg: TypeError: window.editor.infoPanel is undefined Url: chrome://selenium-ide/content/selenium-ide.xul, line: 1, column: 1 onclick#chrome://selenium-ide/content/selenium-ide.xul:1:1
Most likely, this is related to why I cannot see any action in the table.
This problem really bugs me, because I Googled the exact error message and was unable to find a proper solving-system to deal with it. I mention that my clipboard format is already set to HTML.
All suggestions are welcome, and thank you in advance for taking the time to read this.
The Selenium IDE is no more supported and it may be a issue with latest firefox version. If you really want to use it then go back to a older version of firefox