1

I try clicking on the button search but this is not work. Here is the top code :

driver = webdriver.Chrome()
url = "https://www.flashscore.fr/"
driver.get(url)

the code that problem (first version):

buttonSearch = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".header__button--search")))
                 driver.execute_script("arguments[0].click();", buttonSearch)

This code does not what is asked but does not display an error.

So I have chosen a class in the class header__button--search named searchIcon___2C7g3ZD Here it is:

buttonSearch = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".searchIcon___2C7g3ZD")))
driver.execute_script("arguments[0].click();", buttonSearch)

It display this error : selenium.common.exceptions.JavascriptException: Message: javascript error: arguments[0].click is not a function

Why is it not possible of click on the button search from page ?

EDIT : here is code HTML of button search on the page :

<div id="search-window" class="header__button header__button--search"><span class="searchIcon___HyESXZA"><svg class="searchIcon___2C7g3ZD "><title>Search</title><use xlink:href="/res/_fs/build/control-icons-symbols.0acb5c0.svg#icon--search"></use></svg></span></div>

1 Answer 1

1

    buttonSearch = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".header__button--search"))) driver.execute_script("arguments[0].click();", buttonSearch) 

This does not work because you didn't call any method on buttonSearch. For example methods such as buttonSearch.click(), or buttonsearch.doubleClick(), etc. Without calling a method, the error will not be displayed. This is because instead of using the css selector of the element you instead used it's class name.

You then noticed that and amended that issue like so:


    buttonSearch = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".searchIcon___2C7g3ZD")))
    driver.execute_script("arguments[0].click();", buttonSearch)

However, that allowed the element to be located. But the webdriver is now unable to interact with the element. Because in the error it is explicitly stated that arguments[0].click is not a function. So to fix this, instead of of using execute_script simply use click() instead. It's a simpler way, and the intended way. Like this:


    buttonSearch = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".searchIcon___2C7g3ZD"))).click()

Sign up to request clarification or add additional context in comments.

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.