0

I am trying to fill in the search input type box with value "fab" and then I want to display the next url with that keyword but I am getting this error for element not interactable. How can I solve this?

from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome(executable_path='C:\\Users\\Mansi Dhingra\\Downloads\\chromedriver') driver.get("https://www.thenational.ae/search?q=") print(driver.title) driver.implicitly_wait(10) search_bar = driver.find_element_by_xpath('//input[@name="q"]') print(search_bar) search_bar.clear() search_bar.send_keys("fab") search_bar.send_keys(Keys.RETURN) print(driver.current_url) driver.close() 

Error:-

Traceback (most recent call last): File "C:/Users/Mansi Dhingra/Desktop/Projects/api/news/news_python.py", line 10, in search_bar.clear() File "C:\Users\Mansi Dhingra\Desktop\Projects\api\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 95, in clear self._execute(Command.CLEAR_ELEMENT) File "C:\Users\Mansi Dhingra\Desktop\Projects\api\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute return self._parent.execute(command, params) File "C:\Users\Mansi Dhingra\Desktop\Projects\api\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\Mansi Dhingra\Desktop\Projects\api\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable (Session info: chrome=81.0.4044.92)

1 Answer 1

0

Whenever webelement is found but not ready to interact then webdriver will throw element not intractable exception.

1.Mostly it occurs, when element is located in bottom of the page, so it can be accessible by scrolling the page down. You can use Action class to scroll to scroll to that element

WebElement element = driver.findElement(By.id("my-id")); Actions actions = new Actions(driver); actions.moveToElement(element); ## actions.click(); actions.perform(); 

2. Sometimes we need to wait few seconds to access the web element, in such situations we can add wait statements.

wait = WebDriverWait(driver, 10) element = wait.until(EC.element_to_be_clickable((By.ID, 'someid'))) 
Sign up to request clarification or add additional context in comments.

3 Comments

Actually I am new to selenium. Can you help me by embedding your code into mine because I didn't exactly understood where I have to make changes.
I have applied wait function and also search is not the last element. Please it would be very helpful if you could help me with appending changes into my code
Try to add implicit wait statements before the line "search_bar.clear()" and then try

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.