简体   繁体   English

python中的Selenium - 初始化驱动程序

[英]Selenium in python - initializing the driver

I have downloaded the necessary drivers for using selenium in chrome.我已经下载了在 chrome 中使用 selenium 所需的驱动程序。 This is the code I am using:这是我正在使用的代码:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome('./chromedriver')

When I am initialising the variable driver itself, a chrome page is opened.当我初始化变量驱动程序本身时,会打开一个 chrome 页面。 I do not want that to happen.我不希望这种情况发生。 I want to open a chrome page only when I use the driver.get() method.我只想在使用 driver.get() 方法时打开一个 chrome 页面。 How do I do it?我该怎么做?

The driver will open chrome by default.默认情况下,驱动程序将打开 chrome。

If you want to open the chrome by driver.get() method then use the code below:如果您想通过driver.get()方法打开 chrome,使用以下代码:

Try this:尝试这个:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome('./chromedriver')

driver.get(url='http://www.facebook.com')

Pass the url in driver.get()driver.get() 中传递 url

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM