import time
from selenium import webdriver
driver = webdriver.Chrome("../drivers/chromedriver.exe")
driver.get("https://google.com")
driver.find_element_by_name("q").send_keys('Google')
driver.find_element_by_name("btnK").click()
time.sleep(3)
driver.close()
driver.quit()
print("Test completed")
This is the code and I am getting an error like:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=87.0.4280.66)
To click on Google Search button, as the element is within a <form>
you can use the following Locator Strategies:
Using submit()
:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://google.com")
element = driver.find_element_by_name("q")
element.send_keys('Google')
element.submit()
driver.quit()
print("Test completed")
Using send_keys(Keys.RETURN)
:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://google.com")
element = driver.find_element_by_name("q")
element.send_keys('Google')
element.send_keys(Keys.RETURN)
driver.quit()
print("Test completed")
Using send_keys(Keys.ENTER)
:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://google.com")
element = driver.find_element_by_name("q")
element.send_keys('Google')
element.send_keys(Keys.ENTER)
driver.quit()
print("Test completed")
Ideally, to click on Google Search button, you need to induce WebDriverWait for the element_to_be_clickable()
and you can use the following Locator Strategies:
Using submit()
:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://google.com")
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "q")))
element.send_keys('Google')
element.submit()
driver.quit()
print("Test completed")
Using send_keys(Keys.RETURN)
:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://google.com")
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "q")))
element.send_keys('Google')
element.send_keys(Keys.RETURN)
driver.quit()
print("Test completed")
Using send_keys(Keys.ENTER)
:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://google.com")
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "q")))
element.send_keys('Google')
element.send_keys(Keys.ENTER)
driver.quit()
print("Test completed")
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
You can find a couple of relevant detailed discussions in:
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments