Disable the request for geolocation in Opera webdriver? - selenium

Faced c with the fall of tests due to a geolocation request. Please tell me how to launch the browser without this request?
My code is the calling browser:
System.setProperty("webdriver.opera.driver", "C:/src/test/resources/operadriver.exe");
OperaOptions options = new OperaOptions();
options.setBinary(new File("C:/Program Files/Opera/50.0.2762.67/opera.exe"));
driver = new OperaDriver(options);
WebDriverRunner.setWebDriver(driver);

Use below code:
System.setProperty("webdriver.opera.driver", "C:/src/test/resources/operadriver.exe");
OperaOptions options = new OperaOptions();
options.setBinary(new File("C:/Program Files/Opera/50.0.2762.67/opera.exe"));
options.addArguments("--disable-notifications");
driver = new OperaDriver(options);

Related

Selenium Proxy IP Address Configuration IP Not Correct

I have paid/rented a proxy server in brazil
String proxyAddress = "myusername:myuserpass123#196.18.199.51:15464"
proxy.setAutodetect(false);
proxy.setHttpProxy(proxyAddress);
proxy.setSslProxy(proxyAddress);
chromeOptions.setCapability(CapabilityType.PROXY, proxy);
WebDriver webDriver = new ChromeDriver(chromeOptions);
I m running the webdriver on my local computer and I am in Indonesia. When the chrome browser opens up, I can debug and made sure that capabilities were set correctly: I can see the manual proxy setting set to the correct address string above.
However, when webdriver opens https://api.ipify.org/?format=json, it still returns my IP in Indonesia. What am I Missing here? My expectation is because I had configured webdriver to be proxied by a server in Brazil, https://api.ipify.org/?format=json should return Brazilian IP address?
Using Selenium 4 BiDirectional API (https://www.selenium.dev/documentation/webdriver/bidirectional/bidi_api/)
Register Basic Auth.
Some applications make use of browser authentication to secure pages. With Selenium, you can automate the input of basic auth credentials whenever they arise.
//C#
//Console App .NET 6
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
Proxy proxy = new Proxy();
var proxyAddress = "address:port";
proxy.HttpProxy = proxyAddress;
proxy.SslProxy = proxyAddress;
ChromeOptions options = new ChromeOptions();
options.Proxy = proxy;
IWebDriver driver = new ChromeDriver(options);
NetworkAuthenticationHandler handler = new NetworkAuthenticationHandler()
{
UriMatcher = (d) => d.Host.Contains("your-domain.com"), // or set it `true` to enable proxy everywhere
Credentials = new PasswordCredentials("admin", "password")
};
INetwork networkInterceptor = driver.Manage().Network;
networkInterceptor.AddAuthenticationHandler(handler);
await networkInterceptor.StartMonitoring();
driver.Navigate().GoToUrl("https://api.ipify.org/?format=json");
await networkInterceptor.StopMonitoring();

Accept microphone and camera permissions on Edge using selenium

I am running selenium scripts on Edge browser. one of the functionality requires to initiate a audio or video call between two windows. In chrome, we can use 'use-fake-ui-for-media-stream' in chrome options. Is there anything similar for Edge. If there isn't, is there a way to accept these alerts at runtime. I have tried -
driver.switchTo().alert().accept(),
but this also doesn't work, and throws error saying no such alert present
Edited
I am using Edge chromium and java selenium and have set properties as below in code. Still permission pop up shows when script runs
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
prefs.put("download.default_directory", fileDownloadLocation);
EdgeOptions options= new EdgeOptions();
options.setCapability("prefs", prefs);
options.setCapability("allow-file-access-from-files", true);
options.setCapability("use-fake-device-for-media-stream", true);
options.setCapability("use-fake-ui-for-media-stream", true);
DesiredCapabilities capabilities = DesiredCapabilities.edge;
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);
capabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS,true);
System.setProperty("webdriver.edge.driver", getDriverPath("EDGE"));
driver = new EdgeDriver(options);
driver.manage().window().maximize();
I suggest you make a test with the sample code below. I tried to test with the Edge Chromium browser and it looks like it is not asking the permission popup.
JAVA code:
public static void main(String[] args)
{
System.setProperty("webdriver.edge.driver","\\msedgedriver.exe");
EdgeOptions op=new EdgeOptions();
op.addArguments("use-fake-device-for-media-stream");
op.addArguments("use-fake-ui-for-media-stream");
WebDriver browser = new EdgeDriver(op);
browser.get("https://your_URL_here...");
}
In Selenium 3.141 Version we dont have addArguments() method but in Selenium 4.0.0 alpha version we have addArguments() method
EdgeOptions edgeOpts = new EdgeOptions();
edgeOpts.addArguments("allow-file-access-from-files");
edgeOpts.addArguments("use-fake-device-for-media-stream");
edgeOpts.addArguments("use-fake-ui-for-media-stream");
edgeOpts.addArguments("--disable-features=EnableEphemeralFlashPermission");
driver = new EdgeDriver(edgeOpts);

Selenium doesn't call web page in Chrome

I'm using Chrome browser version 57.0.2987.110 and I'm trying to open up a web page with Selenium, only thing is it's only opening the browser with the standard website but is not opening the web page I told it to. It's not an option to change the browser, I have to work with chrome.
I get this error right here:
Request for unknown Channel-associated interface: ui::mojom::GpuMain
I tried this solution so far, but it didn't work for me: Strange error in selenium after upgrading to chromedriver 2.28 needed for chrome 57
This is my code:
public static void main(String[] args) {
WebDriver driver;
String PROXY;
Proxy proxy;
proxy = new Proxy();
PROXY = "proxy.myproxy:8080";
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-gpu");
System.setProperty("webdriver.chrome.driver", "/usr/bin/google-chrome");
proxy.setHttpProxy(PROXY).setFtpProxy(PROXY).setSslProxy(PROXY);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
driver.get("www.facebook.com");
}
I've just been starting with selenium and just wrote down everything really quick to try it out in main class. I know it's not pretty. Please bear with me. What am I doing wrong?
You need to update your both selenium jars and update your chrome browser as well

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);

How to set the PhantomJSOptions in Selenium for proxy-type?

Using Selenium and the web driver to drive phantomjs as part of a web scraping project. From the "Known Issues" for Windows at PhantomJS, it is suggested that the proxy-type be set to "none" to speed up network performance.
I tried the following:
PhantomJSOptions options = new PhantomJSOptions();
options.AddAdditionalCapability("proxy", "{proxyType:none}");
However, this sets proxy to a string and I think I need a json object. Can someone show me how to do this correctly?
Use the driver service to set options:
var phantomJSDriverService = PhantomJSDriverService.CreateDefaultService(phantomJsDir);
phantomJSDriverService.ProxyType = "none";
var driver = new PhantomJSDriver(phantomJSDriverService);