The first part of the code opens Chrome and navigates to GitHub. If I don't find my solution, I open a new tab with ctrlt. Then my code goes to Stack Overflow and searches there for solutions.
from selenium import webdriver
from selenium.webdriver.common.keys import *
import time
import keyboard
q = input("what is your programming question : ")+(' python')
class github :
path = "c:/users/admin/appdata/local/programs/python/python38-32/chromedriver.exe"
driver = webdriver.Chrome(path)
driver.get("https://github.com/")
question = driver.find_element_by_name("q")
time.sleep(3)
question.send_keys(q)
question.send_keys(Keys.RETURN)
while True:
if keyboard.is_pressed("ctrl+t"):
driver.switch_to_window(driver.window_handles[-1])
driver.get("https://stackoverflow.com/")
question_2 = driver.find_element_by_name("q")
question_2.send_keys(q)
question_2.send_keys(Keys.RETURN)
break
https://stackoverflow.com/search?q=test
for the search, instead of finding DOM element, and entering keystrokes ? You can add filters of your own, like tagshttps://stackoverflow.com/search?q=+test+%5Bpython%5D
where%5B
is[
and%5D
is]
\$\endgroup\$