Search code examples
pythonseleniumbuild-automationpython-webbrowser

is it possible to controll browse(any) using python ,


i am trying to control my browser using python, what I need is I give commands in terminal that should work on the browser like opening and searching for something(like scorling the bowser) and closing the browser

currently I am done with opening the browser and closing


Solution

  • yes, you can by using python selenium driver.

    This is simple code to test. Also don't forget to download selenium driver. https://chromedriver.chromium.org/downloads

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    
    driver = webdriver.Chrome('./chromedriver')
    driver.get("https://www.python.org")
    print(driver.title)
    search_bar = driver.find_element_by_name("q")
    search_bar.clear()
    search_bar.send_keys("getting started with python")
    search_bar.send_keys(Keys.RETURN)
    print(driver.current_url)
    driver.close()
    
    

    Read docs in link