如何在 selenium python 中按下打开应用程序按钮

How can I press the open application button in selenium python

你好,如何使用 python 和 selenium

打开打开的 roblox 按钮

代码:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
from csv import DictReader
from selenium.webdriver.chrome.options import Options

options = webdriver.ChromeOptions()
s = Service('C:\Program Files (x86)\chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
def main():
driver.get("https://roblox.com")

def get_cookies_values(file):
    with open(file) as f:
        dr = DictReader(f)
        list_dicts = list(dr)
    return list_dicts
    
cookies = get_cookies_values("roblox_cookies.csv")

for i in cookies:
    driver.add_cookie(i)

driver.refresh()
time.sleep(1)
driver.get("https://web.roblox.com/games/537413528/")
driver.find_element(By.XPATH, '//div[@id="game-details-play-button-container"]').click()

if __name__ == "__main__":
    main()

我不确定使用 selenium 导入是否必要,因为你从未指定过这个,但你可以使用

import webbrowser

如果你有播放按钮的位置,使用pyautogui库

import pyautogui

然后像这样使用 .open() 函数:

webbrowser.open(wp)
pyautogui.click(x, y)
# wp is the webpage you want to open
# x and y should be the parameters of the button pos