当条件满足时,如何从无头镀铬切换到有头镀铬?

2024-06-16 10:46:43 发布

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

有没有可能从无头铬合金切换到有头铬合金,当某个条件得到满足/或某个东西被调用时?在

这是我的代码:

import os  
from selenium import webdriver  
from selenium.webdriver.common.keys import Keys  
from selenium.webdriver.chrome.options import Options

chrome_options = Options()  
chrome_options.add_argument("--headless")  
chrome_options.binary_location = """/Applications/Google Chrome   
Canary.app/Contents/MacOS/Google Chrome Canary"""

driver = webdriver.Chrome(executable_path=os.path.abspath(“chromedriver")) 
chrome_options=chrome_options  
driver.get("http://www.google.com")

我试过删除选项,但似乎不起作用。。。当某个元素出现时,我试图从无头形式切换到有头形式。。。在

^{pr2}$

我知道我总是可以关闭实例并打开一个新实例,但我想知道是否有一种方法可以这样做,所以浏览器基本上是隐藏的,直到满足一个条件。在


Tags: pathfromimportosdriverseleniumgooglechrome