Selenium webdriver without making server of the pc

爷,独闯天下 提交于 2019-12-02 13:43:24

问题


I have read the comments below for this question: What are the differences between 'Selenium-server-standalone.jar' and 'Selenium Client & WebDriver'?

I would like to ask: Can alone run webdriver without server? I only install selenium with "pip install selenium" and downloaded a chrome webdriver from chrome website.

If I run a code like this:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)

then my pc on a network at my workplace will work as a server ? Or my pc will work as normal, like if I just run a python like this without any modul:

print("hello")

I am worry about making a server of my pc at my workplace and cause some issue for my co-workers. I just want some task and process automate, I have a lot of copy-paste task from a website, which can be visited inside the company, so this website cannot be accessed by public. I am not a programmer (but have some experience in python), so I didnt learnt about networks, just an engineer who would like to make simplier/faster the tasks.


回答1:


As per How Does WebDriver ‘Drive’ the Browser Selenium-WebDriver makes direct calls to the browser using each browser’s native support for automation. These direct calls and the features they support depends on the browser you are using.

The WebDriver consists of three separate pieces.

  • First of all, there is the Browser itself (e.g. Firefox / Chrome).
  • Next, the language bindings provided by the Selenium project (i.e. the Driver).
  • The executable downloaded either from GeckoDriver or ChromeDriver repository which acts as a bridge between Browser Client and the Driver. This executable is called WebDriver which we often refer as the Server to keep things simple.

So to execute you test you would require all these three pieces.

  • Mostly you will be having Firefox and Chrome browsers installed in your local system.
  • Start a command prompt using the cmd.exe program and run the pip command as given below to install selenium.

    pip install selenium
    
  • You can find a detailed discussion in Python : no module named selenium

  • The GeckoDriver and ChromeDriver can be downloaded from the respective locations.
  • Now, you can execute your script which is as follows:

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    
    driver = webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe')
    driver.get("http://www.python.org")
    assert "Python" in driver.title
    elem = driver.find_element_by_name("q")
    elem.clear()
    elem.send_keys("pycon")
    elem.send_keys(Keys.RETURN)
    


来源:https://stackoverflow.com/questions/53429669/selenium-webdriver-without-making-server-of-the-pc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!