Can we capture GET responses via ChromeDriver Selenium? - c#

When i navigate a page, the page makes several GET requests. I wonder that, can I capture individual GET requests by using ChromeDriver Selenium?
C# 4.6.2

Selenium itself can't capture network traffic, but you could use it with this embedded proxy and it should work fine.

Related

Selenium: Change Tor circuit

I have a Selenium script that controls a Tor browser. However, I'm unable to use the functionality 'New Tor Circuit for this site' even by sending the Ctrl+Shift+L combination to the browser.
Can someone explain how I can achieve this?
For reference, I'm using C# with the OpenQA Selenium package
The "new circuit" is a Tor Browser behaviour, you can't "launch" it with Selenium, Selenium just acts on the viewport.
But you can anyway launch a terminal command programmatically.
Take a look here
or there: link

Is it possible to open Chrome process and execute javascript on a website in the Chrome window?

For a C# WPF application I'm creating, I would like to open a website in Google Chrome.
Chrome is standalone and totally independent from my application.
I start Chrome like the following:
Process.Start("chrome.exe", "http://www.example.com");
So an independent process is started, which is the Chrome instance that loads the desired web address.
What I would like to do, is running arbitrary javascript code on the loaded webpage. Like if the javascript code would be 'injected'.
I do not control the loaded website.
The purpose is to open a third-party webpage and pre-fill in some form fields so the user doesn't have to do this all time.
Is there any possibility to achieve this?
Yes, I've done this many time using Seleniums's JavaScriptExecutor.
You'll want to launch Chrome using the Selenium Driver instead of launching the Chrome process yourself.
https://www.guru99.com/execute-javascript-selenium-webdriver.html
From their example:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(Script,Arguments);

Repetitive Login Ban Issue (Selenium C#)

I am testing a complicated website and have to login every single time I want to test the required features. I got banned by the website last night and had to wait till the morning to work again. Do you have any suggestion for me that I can import some of the website and run it on local server so that I can complete the work without being banned.
Thank you
Not quite sure if you can export some of the website and run it on local server, but there are a couple of alternatives as follows:
You can use tor as a Browser Client and you can find a couple of relevant discussions in:
How to connect to Tor browser using Python
How to use Tor with Chrome browser through Selenium
You can use make use the rotating proxies marked with in the Last Checked column which gets updated within the Free Proxy List. You can find a couple of related discussions in:
Change proxy in chromedriver for scraping purposes

WebBrowser not executing Google Analytics Javascript

I have a website running locally and I want to test the GA code I have by hitting the website repeatedly (with a delay) using C#'s WebBrowser class. The issue is that the GA code (the event) is sent with $('document').ready() and I cannot for the life of me get WebBrowser to actually load the javascript on the page.
I was able to get this to work by using Chrome or Firefox by using var proc = new Process("firefox.exe", "my-ga-args") and that works, but I'd like to run this in the background while I'm doing other work and even if I modify the process to start minimized it still takes focus away from my main window when it closes and re-opens Firefox (using different GA parameters that I have in a list that its looping through).
So, is there any way to get WebBrowser to actually execute javascript that exists on the webpage and have it hidden from view while running?
I think you're looking for something like Google's Puppeteer or given your C# tag, perhaps the .NET port Puppeteer Sharp.
... library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. Puppeteer runs headless by default, but can be configured to run full (non-headless) Chrome or Chromium.

C# browser automation that will work on server

I have been using WatiN for some browser automation and website testing. Recently I received a request to automate some task that needs to check a partner website for existence of some SKU (since they don't have a proper API) and confirm transaction.
I tried using WatiN, but since this runs on a server and on-demand, the server desktop is naturally locked at most times and the IE window does not open and the process is never run.
I am looking for an alternative to WatiN, which is preferably a .net library (not a must, but just makes things easier), does not require a logged in user and being free and open source is always nice.
Anyone have experience with this type of automation?
You can use the Selenium WebDriver coupled with PhantomJS.
Selenium is similar in many ways to WaitN but it supports more browsers. PhantomJS is a headless browser and wrapped in a portable executable you can run from your web server.
Once you've added the NuGet packages, you will be able to instantiate a PhantomJS web driver and control a site without having to launch a full-fledged browser.
var driver = OpenQA.Selenium.PhantomJS.PhantomJSDriver();
We use this on build servers since the build agents are not logged in and won't be able to launch a normal browser process.
If you just need to check some HTML, you can use WebClient to make a request to the site, return the content response as a string and parse it.

Categories

Resources