Adding ChromeOptions for Selnium Webdriver C#

Home / Uncategorized / Adding ChromeOptions for Selnium Webdriver C#

From what I understand, the default action of when the Webdriver finds an element is to scroll such that the element is as far up the top of the page as possible. This is an issue because the website I’m working on has a header so every time I try to click on a button, it will instead click on the header. Thus, I want to change the scroll setting so that the element will be at the bottom of the page.

From reading this I was able to find what I wanted to set, however, I’m unable to set the DesiredCapabilites or ChromeOptions when I initialise the ChromeDriver. Could some provide code/steps to do this please?

You can use something like this
var chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("intl.accept_languages", "en");
chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");

var driver = new ChromeDriver(chromeOptions);

Edit-2 If the option you want to set doesn’t work for you then try using actions
var elem = driver.FindElements(By.Id("your element"));
Actions action = new Actions(driver);
action.MoveToElement(elem).Click(elem).Perform();//move to list element that needs to be hovered


If the above also doesn’t work then your next option is to use Javascript
var elem = driver.FindElements(By.Id("your element"));

IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
var success = js.ExecuteScript("arguments[0].click(); return true", elem);
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *