Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
228 views
in Technique[技术] by (71.8m points)

Is it possible to simultaneously have chromedriver visible to docker and the user

I'm writing a script which opens up gog.com and then waits for you to press the q key. in the mean time you're supposed to click on a game (which will open up a new page) and then press the q key. once you have done this the name , price and platform of the game are grabbed and printed.

Is it possible to dockerize this. I don't know how to get chromedriver to open up on the users desktop in such a way that docker (or my python script) can see what going on.

the user needs to be able to click around on the browser chromedriver opens, to find the game and the script has to detect keyboard press and be able to see the browser too to get the price

heres my script (if thats useful)

def wait_for_delete():
    thing_chosen = False
    while not thing_chosen:
        if keyboard.is_pressed('q'):
            thing_chosen = True
            
driver_xpath2 = "chromedriver.exe"
driver = webdriver.Chrome(driver_xpath2)

driver.get("https://www.gog.com")
print("now navigate to a game and press q")
wait_for_delete() 

works_on_xp = '//*[@id="pageTop"]/body/div[1]/div[7]/div[4]/div[2]/div[2]/div[2]/div[2]'
price_xp = '//*[@id="pageTop"]/body/div[1]/div[6]/div[2]/div[1]/span[3]'
name_xp = '//*[@id="pageTop"]/body/div[1]/div[6]/div[1]/h1'

WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,works_on_xp)))
works_on = driver.find_element_by_xpath(works_on_xp).get_attribute("innerHTML")

WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,price_xp)))
price = driver.find_element_by_xpath(price_xp).get_attribute("innerHTML")

WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,name_xp)))
name = driver.find_element_by_xpath(name_xp).get_attribute("innerHTML")

print(works_on)
print(price)
print(name)

is this possible? what sort of thing do i need to start learning (im that lost)

question from:https://stackoverflow.com/questions/65919521/is-it-possible-to-simultaneously-have-chromedriver-visible-to-docker-and-the-use

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For the beginning you can use Zalenium - it's a dockerized selenium container where you can connect your tests to run there. Also - you need to connect your driver remotely to that container.

Zalenium Git Hub
How to connect python tests to a grid


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...