2

I am working with the following selenium script:

from selenium import webdriver
PATH= r"C:\Users\Hamid\Desktop\Selenium\chromedriver.exe"
driver=webdriver.Chrome(PATH)
driver.get("https://www.google.com/")
cookie_button=driver.find_element_by_xpath('//*[@id="L2AGLb"]/div').click()

How do I add a command line to enter 'ONS data' onto the google search tab? Also, how can I turn the window into headless mode?

1 Answers1

0

You can send the character sequence to the Google Search area using the following locator strategy:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "q"))).send_keys("ONS data")

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

But once you have initiated in headed mode you won't be able to shift to mode within the same session.

You can find a relevant detailed discussion in How can I switch from headless mode to normal mode using Google Chrome and Selenium?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I entered the code but unfortunately it gives me the following error: WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "q"))).send_keys("ONS data") NameError: name 'WebDriverWait' is not defined Thanks. I'll have a read through the link you shared regarding the headless mode. –  Apr 20 '22 at 23:46
  • @DavidCopperfield Please crosscheck if you have added the desired imports mentioned within the answer? – undetected Selenium Apr 20 '22 at 23:49