Selenium Webdriver无需制作PC服务器 [英] Selenium webdriver without making server of the pc

查看:113
本文介绍了Selenium Webdriver无需制作PC服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读以下有关此问题的评论: "Selenium-server- standalone.jar"和"Selenium Client& WebDriver'?

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

我想问:没有服务器就可以独自运行webdriver吗? 我仅使用"pip install selenium"安装selenium,并从chrome网站下载了chrome 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)

然后我在工作场所的网络上的PC可以用作服务器吗?否则我的电脑将正常工作,就像我只是像这样运行一个没有任何模块的python一样:

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

我担心在我的工作场所中为我的PC创建服务器,这会给我的同事带来麻烦.我只希望一些任务和流程自动化,我从网站上有很多复制粘贴任务,可以在公司内部进行访问,因此该网站不能被公众访问.我不是程序员(但是有一些python的经验),所以我没有学习网络,只是想简化/加快任务的工程师.

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.

推荐答案

按照 Selenium-WebDriver使用每个浏览器的本机自动化支持直接调用浏览器.这些直接调用及其支持的功能取决于您使用的浏览器.

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.

WebDriver由三个独立的部分组成.

The WebDriver consists of three separate pieces.

  • 首先,有浏览器本身(例如 Firefox / Chrome ).
  • 接下来,是 Selenium项目(即 Driver )提供的语言绑定.
  • GeckoDriver ChromeDriver 存储库下载的可执行文件,该存储库充当 Browser Client Driver .该可执行文件称为 WebDriver ,为了简化操作,我们通常将其称为 Server .
  • 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.

  • 大多数情况下,您将在本地系统中安装 Firefox Chrome 浏览器.
  • 使用cmd.exe程序启动命令提示符,并按如下所示运行pip命令以安装硒.

  • 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

  • 您可以在 Python:没有名为selenium的模块中找到详细的讨论

    现在,您可以执行以下脚本:

    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)
    

  • 这篇关于Selenium Webdriver无需制作PC服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆