0
votes

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

1 Answers

0
votes

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')))