I am learning selenium but I can't seem to click the google search button with it. What I am trying:
IWebDriver driver = new ChromeDriver();
driver.Url = "https://google.com";
IWebElement searchBar = driver.FindElement(By.Name("q"));
searchBar.SendKeys("Hello world!");
IWebElement searchButton = driver.FindElement(By.Name("btnK"));
searchButton.Click();
It fills the search bar with hello world properly but an exception while clicking the button: OpenQA.Selenium.ElementNotInteractableException: 'element not interactable
As you are learning, I think it's a good exercise for you where you can use findElements
and then interact with the list item(s).
I can give you the idea then you have to implement it by your self which will give you more information rather just getting the answer.
You have to use findElements
rather findElement
as there are 2 elements with the same exact name
attribute value.
driver.FindElements(By.Name("btnK"))
This will give you list of elements. Then check the size it will be 2. Now click on the 2nd Element.
Or you can just use JavaScript to click on the searchButton
from your original post.
Thanks, this worked for me. Just clicked the last element. var searchButton = driver.FindElements(By.Name("btnK")); searchButton.Last().Click();
And you can upvote as a gratitude and also helps the future visitors to pick which answer worked.