How to add flags to webdrive using JS? - selenium

I want to add this attribute
chrome://flags/#mark-non-secure-as
Part of the webdriver
I saw that I can add with
var capabilities = webdriver.Capabilities.chrome();
Is it the right way ?
If yes which attribute do I need to add this attribute
https://sites.google.com/a/chromium.org/chromedriver/capabilities
The value that I want to pass is Always mark Http as neural , Does it have any constant ?
var TestConfiguration = require("./globalConfiguration"),
webdriver = require('selenium-webdriver'),
proxy = require('selenium-webdriver/proxy');
module.exports = {
createDriver: function () {
var capabilities = webdriver.Capabilities.chrome();
capabilities.chromeOptions = {
args: ['mark-non-secure-as=NEUTRAL']
};
var manualProxy = TestConfiguration.getParam(TestConfiguration.KEYS.PROXY);
var proxyToSet = proxy.system();
if (manualProxy) {
proxyToSet = proxy.manual({http: manualProxy, https: manualProxy});
}
var driver = new webdriver.Builder().withCapabilities(capabilities).
usingServer(TestConfiguration.getParam(TestConfiguration.KEYS.SELENIUM_HOST))
.setProxy(proxyToSet)
.build();
return driver;
}
};

You did not specify whether you are using C# or Java version of the selenium driver but the code is basically the same either way. The c# code below opens chrome with the attribute 'chrome://flags/#mark-non-secure-as' set.
You just need to create a ChromeOptions object set the desired options and pass it to the driver constructor.
https://sites.google.com/a/chromium.org/chromedriver/capabilities
ChromeOptions options = new ChromeOptions();
options.AddArgument("--mark-non-secure-as");
IWebDriver driver = new ChromeDriver(options);
I used version 3.3 of Webdriver.dll and the Chrome driver from: https://sites.google.com/a/chromium.org/chromedriver/getting-started

Related

Additional chrome options for headless mode with Kameleo

Been testing the Kameleo.LocalApiClient now whole day. Noticed something strange.
var client = new KameleoLocalApiClient(new Uri(KameleoBaseUrl));
client.SetRetryPolicy(null);
// Search Chrome Base Profiles
var baseProfileList = await client.SearchBaseProfilesAsync("desktop", "windows", "chrome", "ru-ru");
Random rnd = new Random();
var baseId = rnd.Next(1, baseProfileList.Count);
// Create a new profile with recommended settings
// Choose one of the Firefox BaseProfiles
// You can set your proxy up in the setProxy method
var requestBody = BuilderForCreateProfile
.ForBaseProfile(baseProfileList[baseId].Id)
.SetRecommendedDefaults()
.SetProxy("http", new Server("zproxy.lum-superproxy.io", 22225, "lum-customer-joshua901-zone-zone2", "5inhblkgrzxj"))
//.SetProxy("http", new Server("zproxy.lum-superproxy.io", 22225, "lum-customer-joshua901-zone-russiashared-ip-181.214.180.215", "lqoz0ee2hbvb"))
.SetLauncher("chrome")
//.SetScreen("--window-size", 500, 783)
.Build();
var profile = await client.CreateProfileAsync(requestBody);
// Start the browser
await client.StartProfileAsync(profile.Id);
// Connect to the running browser instance using WebDriver
var uri = new Uri($"{KameleoBaseUrl}/webdriver");
var opts = new ChromeOptions();
opts.AddAdditionalOption("kameleo:profileId", profile.Id.ToString());
opts.AddExcludedArgument("enable-automation");
opts.AddArgument("--window-size=500,783");
opts.AddArgument("disable-infobars");
opts.AddArgument("--incongito");
opts.AddArgument("--disable-extensions");
opts.AddArgument("disable-gpu");
opts.AddArgument("headless");
opts.AddArgument("--ignore-certificate-errors");
opts.AddArgument("no-sandbox");
opts.AddArgument("--silent-launch");
opts.AddArgument("--no-startup-window");
//var webdriver = new RemoteWebDriver(uri, opts);
_driver = new RemoteWebDriver(uri, opts)
I want to add my additional ChromeOptions to my driver, especially be able to run things in "headless" mode.
Even if i define the ChromeOptions above and create the RemoteWebDriver with these options, the chrome browser does still popup and not run as headless.
How come and how do i add my additional options?
The browser is started by Kameleo
The RemoteWebDriver is not starting any browser, just connecting to the already started browser
Because of these, you cannot pass any arguments to the browser with the RemoteWebDriver's options.
There is way to provide additional web driver options. There is a POST /profiles/{guid}/start endpoint which can process additional arguments, options, and preferences when Kameleo is starting the browser. See the documentation or see the example code.
await client.StartProfileWithWebDriverSettingsAsync(profile.Id, new WebDriverSettings
{
Arguments = new List<string> { "mute-audio" },
Preferences = new List<Preference>
{
new Preference("profile.managed_default_content_settings.images", 2),
new Preference("profile.password_manager_enabled.images", 2),
},
AdditionalOptions = new List<Preference>
{
new Preference("pageLoadStrategy", "eager"),
}
});
There are arguments that are not supported and that may cause issues so it is better to contact the team about the arguments.
For example:
opts.AddArgument("--disable-extensions");
This cannot be added, since Kameleo's extension is needed in the browser. If you remove it, the spoofing won't work.
I see you want to use this flag as well:
opts.AddArgument("disable-gpu");
You can simply set WebGL to Block. IT will result in the same.
Currently, there is no opportunity to start the browser in headless mode. But there will be a solution soon.

Katalon keeps open browser when executed as headless

i have automation code in Katalon studio and i want to execute it in headless.
I've already add argument for headless in chromeoptions. I have also executed it in Chrome(headless) mode. But it still open browser and execute it like normal WebUI.
Below is my code :
class My_WebScraper {
ChromeOptions options = new ChromeOptions();
String ProjectDirectory=RunConfiguration.getProjectDir()
String downloadPath = ProjectDirectory+"/Screenshot"
Map<String, Object> chromePrefs = new HashMap<String, Object>()
DesiredCapabilities cap = DesiredCapabilities.chrome()
String popup_dialog = "//div[#role='dialog']"
String General_Button = "//button[text()='{PARAM}']"
String General_Tab_Menu = "//div[#class='gnb']/ul[#class='g_menu' and #id='top1menu']/li/a[text()='{PARAM}']"
String Left_Menu_of_Mainmenu_Pemantauan = "//div[#id='left_menu']/div[#class='clearfix']/aside[#class='sidebar']/nav[#class='sidebar_nav']/ul[#class='metismenu' and #id='menu']/li/ul[#id='left-menu' and #class='LeftMnRow']/li/a/span[text()='Pemantauan Aktivitas']"
String Pemantauan_Aktivitas_expanded = "//div[#id='left_menu']/div[#class='clearfix']/aside[#class='sidebar']/nav[#class='sidebar_nav']/ul[#class='metismenu' and #id='menu']/li/ul[#id='left-menu' and #class='LeftMnRow']/li/a/span[text()='Pemantauan Aktivitas']/../../ul[#aria-expanded='true' and #class='collapse in']/li/a[text()='{PARAM}']"
String FileLog
String filename
def replace(String x,oldc,newc){
String str = new String(x)
return str.replace(oldc, newc)
return str
}
#Given("Login")
def capture_captcha() throws IOException, InterruptedException{
println(downloadPath)
chromePrefs.put("download.default_directory", downloadPath)
options.setExperimentalOption("prefs", chromePrefs)
options.addArguments("--window-size=1920,1080");
options.addArguments("--disable-gpu");
options.addArguments("--disable-extensions");
options.addArguments("–no-sandbox");
options.addArguments("–disable-dev-shm-usage");
options.addArguments("--disable-software-rasterizer");
options.addArguments("--disable-blink-features='BlockCredentialedSubresources'")
options.addArguments("--no-proxy-server")
options.addArguments("--disable-web-security")
options.addArguments("--allow-running-insecure-content")
options.addArguments("--ignore-certificate-errors")
options.addArguments("–-headless");
cap.setCapability(ChromeOptions.CAPABILITY, options)
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true)
options.merge(cap);
System.setProperty("webdriver.chrome.driver", DriverFactory.getChromeDriverPath())
WebDriver driver = new ChromeDriver(options);
driver.get("https://myweb.com");
driver.manage().window().maximize();
WebUI.delay(3)
can anyone help me,please?
thank you
Your test script used the new driver instance, not the driver instance from WebUI keyword.
The solution here is to override the capabilities from which you can refer here

ConnRoutePNames.LOCAL_ADDRESS on selenium phantomjs

Hi with this code i can say to DefaultHttpClient, hey use this interfaceip for connection. So how can i say like this to phantomjsdriver.
note: sorry for my english. not my native language
Example:
DefaultHttpClient httpClient;
try {
HttpParams params = new BasicHttpParams();
params.setParameter(ConnRoutePNames.LOCAL_ADDRESS, InetAddress.getByName(interfaceIp));
httpClient = new DefaultHttpClient(params);
Solution:
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(ConnRoutePNames.LOCAL_ADDRESS, InetAddress.getByName(interfaceIp));
this.driver = new PhantomJSDriver(caps);

How to configure and setup HTMLUNIT with Selenium while using it in C#?

I setup selenium remote driver and run the selenium server.The selenium server running correctly and while I try to run my code using :
var remoteServer = new Uri("http://127.0.0.1:4444/wd/hub");
DesiredCapabilities desiredCapabilities = DesiredCapabilities.Firefox();
desiredCapabilities.IsJavaScriptEnabled = true;
myDriver = new RemoteWebDriver(remoteServer, desiredCapabilities, new TimeSpan(0,1, 30));
No error throws in the CMD log and elements can find properly, but headache comes while I try to run this using the below code :
var remoteServer = new Uri("http://127.0.0.1:4444/wd/hub");
DesiredCapabilities desiredCapabilities = DesiredCapabilities.HtmlUnit();
desiredCapabilities.IsJavaScriptEnabled = true;
myDriver = new RemoteWebDriver(remoteServer, desiredCapabilities, new TimeSpan(0, 1, 30));
in log it throws lots of error and while I try to find any element, timeout exception showing in log.
My test code is in below :
myDriver.Manage().Window.Maximize();
myDriver.Navigate().GoToUrl(tollFreeURL);
IWebElement planClick = myDriver.FindElement(By.ClassName("trial"));
planClick.Click();
IWebElement startPlan = myDriver.FindElement(By.Id("choose2000"));
startPlan.Click();
IWebElement selectValue = myDriver.FindElement(By.Name("AreaCode"));
var selectElement = new SelectElement(selectValue);
selectElement.SelectByValue("800");
IWebElement selectNumber = myDriver.FindElement(By.XPath("//*[#id='divList']/div[1]"));
tollFreeNumber = selectNumber.Text;
tollFreeNumber = stringConvert.StringRefiner(tollFreeNumber, " ");
tollFreeNumber = stringConvert.StringRefiner(tollFreeNumber, "(");
tollFreeNumber = stringConvert.StringRefiner(tollFreeNumber, ")");
tollFreeNumber = stringConvert.StringRefiner(tollFreeNumber, "-");
Console.WriteLine(tollFreeNumber);
My target is to run the application in background and generate data, so I do not have any option to run this using Firefox.HTMLUNIT is the only option for me.Help needed it will stuck me last 3-4 days.
I believe your machine is using proxy servers. Try by adding that proxy configuration while creating driver instance.
String PROXY = "xx.xx.xx.xx:8080";
OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
proxy.HttpProxy=PROXY;
proxy.FtpProxy=PROXY;
proxy.SslProxy=PROXY;
Add proxy setting to desired Capabilities:
desiredCapabilities.SetCapability(CapabilityType.PROXY, proxy);

how would I run Selenium test through the GRID using C#

i have just set-up the selenium grid on my local machine and everything seems to be up and running.
my question is, is there a way I can run the test case from selenium grid node (command prompt)?
I am using WebDriver for creating my testcase using .Net
Sample code from here
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
// Requires reference to WebDriver.Support.dll
using OpenQA.Selenium.Support.UI;
class GoogleSuggest
{
static void Main(string[] args)
{
// Create a new instance of the Firefox driver.
// Notice that the remainder of the code relies on the interface,
// not the implementation.
// Further note that other drivers (InternetExplorerDriver,
// ChromeDriver, etc.) will require further configuration
// before this example will work. See the wiki pages for the
// individual drivers at http://code.google.com/p/selenium/wiki
// for further information.
WebDriver driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"),
DesiredCapabilities.FirefoxDriver());
//Notice navigation is slightly different than the Java version
//This is because 'get' is a keyword in C#
driver.Navigate().GoToUrl("http://www.google.com/");
// Find the text input element by its name
IWebElement query = driver.FindElement(By.Name("q"));
// Enter something to search for
query.SendKeys("Cheese");
// Now submit the form. WebDriver will find the form for us from the element
query.Submit();
// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });
// Should see: "Cheese - Google Search"
System.Console.WriteLine("Page title is: " + driver.Title);
//Close the browser
driver.Quit();
}
}
WebDriver driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"),
DesiredCapabilities.FirefoxDriver());
OR in c#
IWebDriver driver;
DesiredCapabilities capability = new DesiredCapabilities();
driver = new RemoteWebDriver(
new Uri("http://hub-cloud.com/wd/hub/"), capability);
driver.Navigate().GoToUrl("http://www.google.com");