在python小部件中加载Selenium chrome实例

时间:2019-01-05 02:02:03

标签: python selenium tkinter

有任何python组件 做这样的事情(这是java)

elsewhere on CrossValidated

我使用python tkinter在点击按钮上打开chrome实例, 我想点击按钮在python小部件中运行selenium chrome实例, 在python gui app顶部的一个按钮上,当您单击它时,在tkinter框架中打开selenium chrome实例 是否可以使用python GUI做类似的事情

非常感谢

1 个答案:

答案 0 :(得分:0)

是的,我会尝试这样的事情:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import WebDriverException

#Your paths and driver might be different.
CHROME_PATH = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' 
CHROMEDRIVER_PATH = 'chromedriver.exe'
WINDOW_SIZE = "1920,1080"

chrome_options = Options()
chrome_options.add_argument("--log-level=3")
chrome_options.add_argument("--headless") # This is optional, but faster than gui
chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)
chrome_options.binary_location = CHROME_PATH

browser = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, chrome_options=chrome_options)

url = "https://www.example.com" # Your url goes here.
browser.get(url)
# - You'll need to copy the button's xpath and place it in here.
element = WebDriverWait(browser, 10).until(
                    EC.presence_of_element_located((By.XPATH, 'copy_xpath_into_here'))) 

# click on button - You'll need to copy the button's xpath and place it in here, too.
selectElem=browser.find_element_by_xpath('copy_xpath_into_here').click()