Home > Enterprise >  How do I enter a type command onto my selenium script and also turn it into headless mode?
How do I enter a type command onto my selenium script and also turn it into headless mode?

Time:04-21

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?

CodePudding user response:

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?

  • Related