I managed to use PowerShell 7.1 and Selenium WebDriver and Module to control the Chrome Browser. I need now to access the network response of a post request which will be invoked after the button is clicked from Selenium.
I found some good info here, here, here, and here , however, it is for Python and Java so I need to convert some code to PowerShell. I hope you can help me out.
The code snippet below from one of the above-mentioned sources is where I am having difficulties with:
...
options = webdriver.ChromeOptions()
options.add_argument("--remote-debugging-port=8000")
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=options)
dev_tools = pychrome.Browser(url="http://localhost:8000")
tab = dev_tools.list_tab()[0]
tab.start()
...
Specifically, this part dev_tools = pychrome.Browser(url="http://localhost:8000")
Below is another code snippet I got from one of the above-mentioned sources:
ChromeDriver driver = new ChromeDriver();
DevTools devTool = driver.getDevTools()
devTool.createSession();
devTool.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));
devTool.addListener(Network.responseReceived(), <lamda-function>)
So it is clear the Selenium 4 has support for DevTools, but I am not finding the main C# documentation so that I can use it with PowerShell.
Finally, after accessing the response, I need to verify it using PowerShell Pester.
I appreciate your help.
pychrome
? Are you already using something like theselenium-powershell
module or just straight C#? This might be an example of what you're looking for: https://mcmap.net/q/162467/-how-to-call-this-function-devtools-selenium-c/7411885 – ForestationDevTools
documentation and examples here - select the csharp tab: selenium.dev/documentation/webdriver/bidirectional/… – Forestation$logs = $driver.manage().logs().get("performance")
when you have network logging enabled as detailed here: https://mcmap.net/q/159642/-how-to-get-http-response-code-using-selenium-webdriver – Forestation...logs().get(...)
give me the response of a post request? – Preparative$driver.getPageSource()
, or$driver.switchTo().frame()
, though this would not be specific to an individual request. It probably depends on what you're looking for. – Forestation