Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading