Using Selenium C# DevTools how to capture f12 options (Network) with c# - selenium

Capture F12 options using Selenium C# DevTools, need help on C# SELENIUM, Attached snapshot
Using Selenium C#, collect logs from F12 options on any website,
For example open google.com in chrome and press F12, right side you will see developer options, capture those network logs using selenium C#. Attached snapshot what to capture

Here is the code to access the Network tab. Below code block the css/jpg/png image on the website, you can use any Network method to collect logs or implement according to the requirement.
chromeDriver = new ChromeDriver();
IDevTools devTools = iConstants.chromeDriver as IDevTools;
IDevToolsSession session = devTools.GetDevToolsSession();
var domains = session.GetVersionSpecificDomains<DevToolsSessionDomains>();
await domains.Network.Enable(new Network.EnableCommandSettings());
await domains.Network.SetBlockedURLs(new DevTools.Network.SetBlockedURLsCommandSettings()
{
Urls = new string[] { "*://*/*.css", "*://*/*.jpg", "*://*/*.png" }
});
chromeDriver.Manage().Window.Maximize();
chromeDriver.Url = "https://google.com";

Related

edge web driver cant open whatsapp web

im trying this code to open web.whatsapp.comm on my edge driver
var options = new EdgeOptions();
options.AddArgument(#"user-data-dir= .......");
options.AddExcludedArgument("enable-automation");
options.LeaveBrowserRunning = true;
EdgeDriverService driverService = EdgeDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
var driver = new EdgeDriver(driverService, options);
driver.Navigate().GoToUrl("https://web.whatsapp.com/");
it load normaly first time and i log in my whatsapp account by scanning QR-code, and it work normal.
second time, i close program and run again and it shoud login directly becuse i save profile by option argument.
but in secend time web page does not load and stock on loading page.
im using edge browser version 103.0.1264.44 and driver version 103.0.1264.44

ChromeDriver Access To Mic/Camera For Selenium Test

I’m trying to run an end to end test for a video chat platform, using the ChromeDriver. I need to use the actual webcam stream on my computer to run the test. I’ve tried both versions of the following code, but neither actually defaults the mic/camera settings to allow.
let options = new Options();
options.set("preferences.profile.content_settings.exceptions.media_stream_camera.'<localhost-address>,*'.setting", 1)
options.set("preferences.profile.content_settings.media_stream_mic.'<localhost-address>,*'.setting", 1);
let driver = await new Builder().setChromeOptions(options).forBrowser("chrome").build();
let options = new Options();
options.setUserPreferences({"preferences.profile.content_settings.exceptions.media_stream_camera.'<localhost-address>,*'.setting": 1,
"preferences.profile.content_settings.media_stream_mic.'<localhost-address>,*'.setting": 1});
let driver = await new Builder().setChromeOptions(options).forBrowser("chrome").build();
The pop-up still comes up and I can’t find a way to interact with it. Using a fake device/UI doesn’t resolve the issue, because it’s incompatible (to my knowledge) with Twilio, which the platform also uses.
Does anyone know how to default the ChromeDriver to allow camera/mic access during testing?
Update: The following code runs so that the pop up doesn't appear. But when the driver gets to the point that pop up would show up, the browser instance quits and the test ends. Is it impossible to stream from a webcam via Selenium?
let options = new Options();
options.setUserPreferences({"profile.default_content_setting_values.media_stream_mic": 1,
"profile.default_content_setting_values.media_stream_camera": 1});
let driver = await new Builder().setChromeOptions(options).forBrowser(browser).build();

protractor not able to open new tab window which contains pdf tab

While testing one angular website there is button, When i am clicking on it - It should open new tab which contains pdf.
What i tried - Manual Execution working properly
1) I used JAVA script Executor but it's not working.
browser.executeScript("document.querySelector('My Query Selector').click();");
2) simple click also not opening new tab in chrome protractor testing
const elm = element(by.xpath("//button[#class='My Class Name']"));
elm.click();
chrome Version = Version 74.0.3729.169 (Official Build) (64-bit)
browser.addMockModule('Infrastructure.SignalR', () => {
angular.module('Infrastructure.SignalR', []);
});
does this browser.addMockModule affects to not opening new tab ?
Try using Control+Click to check whether it is working.
const elm = element(by.xpath("//button[#class='My Class Name']"));
Actions action=new Actions(driver);
action.keyDown(Keys.CONTROL).click(elm).keyUp(Keys.CONTROL).build().perform();

Selenium- Popup got blocked if I clicked Link using Javascript Executor in Chrome browser

Problem Description - Upon clicking a link on the page, popup got blocked automatically.
file = new File("tools/chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
caps.setCapability("ignoreZoomSetting", true);
caps.setCapability("nativeEvents", false);
driver = new ChromeDriver(caps);
Environment used – Selenium WebDriver – 2.43.0 ChromeDriver, Windows 7
Note – it is working fine on Firefox & IE, this issue is happening on Chrome only.
Please assist on this.
This is a Chrome Option to disable all popups for the site
Open Chrome.
Find a page that has pop-ups blocked for you.
At the end of the address bar, click the pop-up blocker icon chrome op-up
locked.
Click the link for the pop-up window you'd like to see.
To always see pop-ups for the site, select Always show pop-ups from [site].
Once you have this set use the profile it is saved against to load for the test
Another option is to open the site and Shift F5 to do a Cache Refresh
Load a Profile. The code below is C# and you haven't specified a language. Please see the links provided for Java examples
ChromeOptions options = new ChromeOptions();
userDataPath = "C:/Users/user_name/AppData/Local/Google/Chrome/User Data";
options.AddArguments("user-data-dir=" + userDataPath);
options.AddArguments("--start-maximized");
driver = new ChromeDriver("pathToChromeDriver", options);
You can pass the chromeOption to allow pop-up as shown in below:
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.popups", 1);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);

Windows Internet Explorer Modal dialog box preventing selenium test run

I am trying to execute test cases in IE 8. But sometimes I am getting Windows Internet Explorer Security Warning "Do you want to enable the security content for this page" or Modal dialog box "Stop running this script...". How do I handle it in selenium Webdriver. Any help will be greatly appreciated.
There is an option in InternetExplorerOptions which gives you the opportunity to automatically close the modal if unexpected.
This is how I handle in C# and this should be fairly similar in Java or other bindings as well.
var options = new InternetExplorerOptions { EnableNativeEvents = false };
options.EnsureCleanSession = true;
//This is the main hook
options.AddAdditionalCapability("disable-popup-blocking", true);
Driver = new InternetExplorerDriver(options);