在pythonwidg中加载selenium chrome实例

2024-10-01 02:28:02 发布

您现在位置:Python中文网/ 问答频道 /正文

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

https://jxbrowser.support.teamdev.com/support/solutions/articles/9000013135-jxbrowser-selenium

我用pythonttkinter在点击按钮上打开chrome实例, 我想在python小部件中通过单击按钮运行selenium chrome实例, 在PythonGUI应用程序的顶部有一个按钮,当您单击它时,在tkinter框架中打开selenium chrome实例 有没有可能用pythongui做类似的事情

非常感谢


Tags: 实例httpscomsupportselenium组件javachrome
1条回答
网友
1楼 · 发布于 2024-10-01 02:28:02

是的,你可以,我会试试这样的方法:

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()

相关问题 更多 >