Warm tip: This article is reproduced from stackoverflow.com, please click
c# selenium selenium-chromedriver webdriver

Google search button click with selenium

发布于 2020-03-27 10:21:26

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

Questioner
daaax issa
Viewed
83
supputuri 2019-07-03 12:13

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.