Like my title says, I am looking for a way to mute any audio on Selenium Chrome Web Driver.
I found this for python(example below) and was wondering if there was something similar for C#?
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--mute-audio")
Try this:
var options = new ChromeOptions();
options.AddArgument("mute-audio");
var driver = new ChromeDriver(options);
Related
I tried to send messages to whatsapp with Selenium and C#.
The problem is that, if as an example I am connected to Whatsapp in the current Chrome profile, when the WebDriver is initialized it open a new chrome, without profile and with whatsapp scan QR code.
I want to send messages using the existing browser connection.
I have tried:
var chromeOptions = new ChromeOptions();
chromeOptions.AddExcludedArgument("enable-automation");
chromeOptions.AddAdditionalChromeOption("useAutomationExtension", false);
driver = new ChromeDriver(chromeOptions);
driver.Navigate().GoToUrl("https://web.whatsapp.com/");
And also:
var chromeOptions = new ChromeOptions();
chromeOptions.AddExcludedArgument("enable-automation");
chromeOptions.AddArgument("--user-data-dir=chrome-data");
chromeOptions.AddAdditionalChromeOption("useAutomationExtension", false);
driver = new ChromeDriver(chromeOptions);
driver.Navigate().GoToUrl("https://web.whatsapp.com/");
What I want: to open a new chrome instance, with the existing whatsapp connection,
You need to load the correct profile.
This is the answer provided from uzumaki on how to achieve that:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_argument(r"--user-data-dir=C:\path\to\chrome\user\data") #e.g. C:\Users\You\AppData\Local\Google\Chrome\User Data
options.add_argument(r'--profile-directory=YourProfileDir') #e.g. Profile 3
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")
Im trying to set the default download directory to some thing like:
_webServerFolderDirectory = #"D:\Web\FreshPlatformRegression1\RegressionTestResources";
but i am having no luck finding anything anything to do so. I can find solutions for ChromeDriver (See the line i commented out) but nothing that'll work with DesiredCapabilities for RemoteWebDriver. Here is what the part the calls up the RemoteWebDriver looks like at the moment:
DesiredCapabilities cap = new DesiredCapabilities();
//cap.AddUserProfilePreference("download.default_directory", _webServerFolderDirectory);
cap.SetCapability(CapabilityType.BrowserName, "chrome");
_parallelConfig.Driver = new RemoteWebDriver(new Uri("http://192.168.1.98:4455/wd/hub"), cap);
Incase anyone comes across this issue, I have found a solution. You can use .ToCapabilities() to convert ChromeOptions to capabilities. The code would look similar to this:
String downloadFilepath = #"\\rslfgweb\FreshPlatformRegression1\RegressionTestResources\PDFReports\";
ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("download.default_directory", downloadFilepath);
_parallelConfig.Driver = new RemoteWebDriver(new Uri("http://192.168.1.98:4455/wd/hub"), options.ToCapabilities());
I try to download a ".cert" file which my Chrome identify to be malicious or has potential to harm my PC. Is there a possibility to disable the following box:
Popup Box.
I have searched and tried a ton of possible workarounds or solutions, but none of them worked so far. My Chromeoptions are like that:
var chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("download.default_directory", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
chromeOptions.AddUserProfilePreference("download.prompt_for_download", false);
chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");
chromeOptions.AddUserProfilePreference("download.directory_upgrade", true);
chromeOptions.AddUserProfilePreference("safebrowsing.enabled", true);
I am using the following Nuget pakages:
Selenium WebDriver Version 3.9.1
Selenium.Chrome.Webdriver Version 2.37
Best Regards,
Kandey
This works using Selenium.WebDriver 3.11.2 and Selenium.Chrome.WebDriver 2.37.0 along with disabling download protection. The blank .crt is still hosted on my blog so you can test if you like.
ChromeOptions options = new ChromeOptions();
options.AddArgument("--safebrowsing-disable-download-protection");
options.AddUserProfilePreference("safebrowsing", "enabled");
using (var driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(AppDomain.CurrentDomain.BaseDirectory), options))
{
driver.Url = "https://www.kitson-online.co.uk/test.crt";
}
Chrome v.85, webdriver v.3.141
Worked for me:
ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("safebrowsing", "disabled");
driver = new ChromeDriver(Environment.CurrentDirectory, options);
In Selenium using Webdriver and C# how we can change the browser title?
Using javascript and jQuery as follow:
document.title='XXX'
or
$('title')[0].text='XXX'
Have no effect although we can change the title using Web developers tool console.
Is there any restriction in changing browser title in Selenium?
UPDATE:
Problem roots: Using JavaScriptExecutor that has been initialized with the driver on a window which had been closed.
As said in this answer,
you can run javascript code from selenium.
Your code will be like this:
WebDriver driver; // assume assigned elsewhere
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
string title = (string)js.ExecuteScript("document.title = 'hello'");
And it will change browser title.
Edit
Here full working code:
ChromeOptions options = new ChromeOptions();
options.AddArguments("--start-maximized");
var driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("http://www.google.com");
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
string title = (string)js.ExecuteScript("document.title = 'hello'");
And here result:
To mimic functionality of how my Firefox profile is set up, I need to ensure that the PDF viewer for Chrome is disabled. after searching across the internet, the closest answer I find is here
https://code.google.com/p/chromium/issues/detail?id=528436
However attempting any of the suggestions on this page have given me no success
Here is a snippet of code I expect to work
Dictionary<String, Object> plugin = new Dictionary<String, Object>();
plugin.Add("enabled", false );
plugin.Add("name", "Chrome PDF Viewer");
var options = new ChromeOptions();
options.AddUserProfilePreference("plugins.plugins_list", plugin);
driver = new ChromeDriver(options);
Can anyone see what exactly I am doing wrong? this is starting to become a really frustrating issue!
For Chrome 57, I had to use this line instead:
options.AddUserProfilePreference("plugins.always_open_pdf_externally", true);
Additionally, if you ever need to set a plugin yourself you can find it like this:
Navigate to chrome://settings/content (Menu > Settings, Show advanced settings..., Content settings...).
Locate the specific preference (checkboxes only).
Right-click and Inspect the checkbox.
The preference name is the entire 'pref' attribute's value.
I found that this works for Selenium.WebDriver 2.53m, ChromeDriver 2.25.426923, and Chrome v55.0.2883.87 m.
var options = new ChromeOptions();
options.AddUserProfilePreference("plugins.plugins_disabled", new []{"Chrome PDF Viewer"});
driver = new ChromeDriver(options);
This work for me (if the first link is Chrome PDF Viewer )
driver.Navigate().GoToUrl("chrome://plugins/");
Thread.Sleep(4000);
driver.FindElement(By.LinkText("Disable")).Click();