Capture JSON response through Selenium - selenium

I'm testing a webpage using Selenium (either IDE or webdriver). The webpage has a "search" function, basically just a GET call with params. The javascript also output to console the JSON returned from the search call, i.e. something like console.log(data). And I'm able to inspect the response data in Firefox console.
My question is: is there anyway I can capture this data from Firefox console in Selenium (so that I can further inspect and doing asserts)? Writing a direct GET request (eg, from Python) does not work since the search url is protected through a login page.
Thanks.

AFAIK Selenium doesnt provide any in built API/method to play with console.
You can redirect console output file and read from file.
Link: How to redirect Firefox console output to file.

It was possible at one point using Firebug. Not sure if it still works.

Related

Is it possible to use Selenium in python to get the curl of a media file in chrome?

In Chrome inspector, there is the functionality to get the cURL of a media file. Is it possible to automate the same operation in Selenium by using python? Thank you!
find the URL of the image by finding the image element with find_element* and then get the "href" attribute with get_attribute
cookies can be retrieved via driver.get_cookies()
I think the headers you would have to construct yourself
and at the end you would have to put it all together in a cURL request

OWASP ZAP - Extract URL after browser is launched using Selenium Python

I'm launching a website using Selenium Python! On loading the Chrome browser, ZAP proxy is getting attached to it and capturing URL. I have 2 things to that needs to be clarified here:
How to capture URL/requests when user parses through different links? ZAP is capturing it in GUI. Is there any API that gives me the full URL List?
How to use Selenium (Python) to capture URL? It captures only current URL and when I go to other link, it doesn't print the new page URL.
The short answer is yes - Zap has an amazing API, and you can find the documentation here. For a longer explanation, I will need some details as I don't fully understand your question.
1 - are you looking to get all the request that were proxy through Zap? You can use the following: /JSON/core/view/sites/?zapapiformat=JSON&formMethod=GET.
2 - Not sure - seems like a selenium question, correct?

get cookies from a website

What are the ways of getting the cookies from a website from ways other than the following?
Inspecting the browser
Using Selenium web drivers by using driver.get_cookies() command
you can also run javascript via selenium and use document.cookie.
it return the cookies in string format:
key=value;key=value

How to pass a message from a webpage to a Safari extension (background/injected)?

It looks like that there is no way to pass a message from the script already in a webpage to a injected script or background page in a Safari extension.
Quite weird if true.
window.postMessage allows you to send a message to the extension scripts on the same page.

Selenium testing with HTML Selenese

I am doing some testing in Selenium using the selenium maven plugin and HTML selenese scripts.
Everything works pretty well except for this scenario I have:
I am clicking on a submit button and it takes me to a redirect url. The server for that URL is not running but the web service that redirect the URL create a code query parameter and add it to the redirect URL.
I want to be able to click submit and use storeLocation selenese command to extract the redirect url and extract that code parameter. When I use clickAndWait, the redirect happens but the test fails because the page tries to load and eventually the maven build. When I use just click command, the test passes, but the page doesn't load and storeLocation doesn't contain the value of the redirect url I need with the code parameter.
Anyone know how to get selenium to click and wait but IGNORE the fact that the page will not load?
I think it needs to involve some javascript and maybe the use of waitForCondition command but I can't find any example of it being done.
basically, the redirect URL has no server running it, but my service create a token param that I need to extract from and pass it to another test case
Is the page load timing out? If so you could increase the default timeout (should be 30 seconds though) or you can use the click event, and then do a waitForLocation to match the new URL (with redirect parameter) you want. This will give you another wait for (like click and wait) of 30 seconds. But you can also add a pause command between the click and the wait for to extend your time for the page to load without touching the default time out.