3

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?

2 Answers 2

3

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

Edit-3

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);
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for this but this doesn't set the default scrolling to be at the bottom
I tried 'elementScrollBehaviour' but it doesn't work as expected
I originally tried using actions but they don't seem to work for me either :/
0

As far as I know you can't change everything through addarguments. There is a list of what you can do in the Github page. but I have a better solution. you can make your own default settings and save it as a chrome profile. for example I didn't find anything to change homepage with code but this works fine for almost evwerything.

you can use this code :

options.AddArguments( @"user-data -dir=C:\Users\kian\AppData\Local\Google\Chrome\User Data"); options.AddArgument("--profile-directory=Default");

make sure you write the right path and right profile name. to check the profile name you can go to properties. properties

you will see the profile name.

there is a good guide for what else u can do in link.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.