如果您想了解我们如何在colab.research.google.com中使用SeleniumWebdriver?的相关知识,那么本文是一篇不可错过的文章,我们将对googlecolab怎么用进行全面
如果您想了解我们如何在colab.research.google.com中使用Selenium Webdriver?的相关知识,那么本文是一篇不可错过的文章,我们将对google colab怎么用进行全面详尽的解释,并且为您提供关于cucumber; Selenium WebDriver-如何使用Google Chrome浏览器代替Firefox作为测试浏览器、java – 如何用selenium webdriver发送cookies?、org.openqa.selenium.remote.service.DriverService $ Builder.createArgs()Lcom /google / common / collect / ImmutableList; 使用Selenium 3.5.3 Chrome 76、ruby – 如何在无头Chrome上使用Selenium Webdriver?的有价值的信息。
本文目录一览:- 我们如何在colab.research.google.com中使用Selenium Webdriver?(google colab怎么用)
- cucumber; Selenium WebDriver-如何使用Google Chrome浏览器代替Firefox作为测试浏览器
- java – 如何用selenium webdriver发送cookies?
- org.openqa.selenium.remote.service.DriverService $ Builder.createArgs()Lcom /google / common / collect / ImmutableList; 使用Selenium 3.5.3 Chrome 76
- ruby – 如何在无头Chrome上使用Selenium Webdriver?
我们如何在colab.research.google.com中使用Selenium Webdriver?(google colab怎么用)
我想在colab.research.google.com中使用Chrome的Selenium
Webdriver进行快速处理。我可以使用安装Selenium,!pip installselenium
但chrome的webdriver需要通向webdriverChrome.exe的路径。我应该如何使用它?
PS-
colab.research.google.com是一个在线平台,可为与深度学习相关的快速计算问题提供GPU。请避免使用诸如webdriver.Chrome(path)之类的解决方案。
答案1
小编典典您可以通过安装Chrome Web驱动程序并调整一些选项来做到这一点,以使其在Google colab中不会崩溃:
!pip install selenium!apt-get update # to update ubuntu to correctly run apt install!apt install chromium-chromedriver!cp /usr/lib/chromium-browser/chromedriver /usr/binimport syssys.path.insert(0,''/usr/lib/chromium-browser/chromedriver'')from selenium import webdriverchrome_options = webdriver.ChromeOptions()chrome_options.add_argument(''--headless'')chrome_options.add_argument(''--no-sandbox'')chrome_options.add_argument(''--disable-dev-shm-usage'')wd = webdriver.Chrome(''chromedriver'',chrome_options=chrome_options)wd.get("https://www.webite-url.com")
cucumber; Selenium WebDriver-如何使用Google Chrome浏览器代替Firefox作为测试浏览器
对于我的Rails 3.1应用程序上的Cucumber场景,我使用了@javascript标记,因此Selenium已激活。我收到以下错误:
Could not find Firefox binary (os=macosx). Make sure Firefox is installed or set the path manually with Selenium::WebDriver::Firefox::Binary.path= (Selenium::WebDriver::Error::WebDriverError)
如果可能的话,我想使用Google Chrome浏览器作为浏览器-而不是Firefox(我尚未安装)。这可能吗?该怎么办?
实际上,Cucumber / Selenium不应检测并使用浏览器吗?
====编辑====
添加后
Capybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new(app, :browser => :chrome)end
…到features / support / env.rb,我现在收到此错误:
Unable to find the chromedriver executable. Please download the server from http://code.google.com/p/chromium/downloads/list and place it somewhere on your PATH. More info at http://code.google.com/p/selenium/wiki/ChromeDriver. (Selenium::WebDriver::Error::WebDriverError) ./features/step_definitions/web_steps.rb:45:in `/^(?:|I )am on (.+)$/'' features/update_memories.feature:11:in `Given I am on the home page''
我是从这里下载的,并且尝试将chromedriver可执行文件放在/
usr / bin中,但是仍然出现上述错误。
====编辑2 ====
进一步执行以下步骤并运行“ sudo chmod + x / usr / bin / chromedriver”后,在运行黄瓜之后,我现在收到一个新错误:
@javascript Scenario: navigate to memory update page from home page # features/update_memories.feature:11 Given I am on the home page # features/step_definitions/web_steps.rb:44 unable to connect to chromedriver http://127.0.0.1:57870 (Selenium::WebDriver::Error::WebDriverError) ./features/step_definitions/web_steps.rb:45:in `/^(?:|I )am on (.+)$/'' features/update_memories.feature:12:in `Given I am on the home page'' When I activate the edit memory switch for the memory "I played" # features/step_definitions/memories/memory_steps.rb:5 Then I should be on the edit memory page for the memory "I played" # features/step_definitions/web_steps.rb:187 PGError: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. : ROLLBACK (ActiveRecord::StatementInvalid)
帮助赞赏!越来越近…
答案1
小编典典对于水豚,将其添加到 env.rb
Capybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new(app, :browser => :chrome)end
下载Chrome驱动程序可执行文件并将其复制到您的路径中,例如
/ usr / bin / 并使其可执行
$ sudo chmod +x /usr/bin/chromedriver
java – 如何用selenium webdriver发送cookies?
如何通过登录操作?
使用Chrome和Firefox驱动,使用java语言.
解决方法
Cookie ck = new Cookie("name","value"); driver.manage().addCookie(ck);
使用Python API创建Cookie如下:
driver.add_cookie({'name': 'foo','value': 'bar'})
org.openqa.selenium.remote.service.DriverService $ Builder.createArgs()Lcom /google / common / collect / ImmutableList; 使用Selenium 3.5.3 Chrome 76
我正在用IntelliJ编写Selenium
Junit测试。如果我直接从测试中触发,则测试运行正常。但是,如果我使用JunitCore触发了来自TestRunnerSuite的测试,则会遇到以下奇怪的错误,在谷歌搜索后我找不到解决方案。在DriverService
$ builder上有类似的问题,但不是我的错误类型。
[main] ERROR sire.responseOrg.TestIncidents - java.lang.AbstractMethodError: org.openqa.selenium.remote.service.DriverService$Builder.createArgs()Lcom/google/common/collect/ImmutableList;
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:332)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at sire.responseOrg.WebDrivers.getInstance(WebDrivers.java:15)
at sire.responseOrg.util.util1.setupChromeDriver(util1.java:51)
at sire.responseOrg.Test1.setUp(Test1.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at ......Omitted
at org.junit.runner.JUnitCore.run(JUnitCore.java:127)
at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:76)
at sire.responseOrg.TestSuiteRunner.main(TestSuiteRunner.java:24)
我正在使用Selenium 3.5.3和 chrome76。— >已更新为Selenium 3.141.59,并具有main
范围。
现在出现错误
java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials
at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:93)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:72)
at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:63)
at org.openqa.selenium.chrome.ChromeDriverCommandExecutor.<init>(ChromeDriverCommandExecutor.java:36)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at sire.responseOrg.WebDrivers.getInstance(WebDrivers.java:15)
at sire.responseOrg.util.SeleniumUtil.setupChromeDriver(SeleniumUtil.java:62)
at sire.responseOrg.TestIncidents.setUp(TestIncidents.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
at org.junit.runner.JUnitCore.run(JUnitCore.java:127)
at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:76)
at sire.responseOrg.TestSuiteRunner.main(TestSuiteRunner.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.http.auth.Credentials
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 33 more
完整的pom.xml依赖项
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myGroupId</groupId>
<artifactId>myArtifactId</artifactId>
<version>1.0-SNAPSHOT</version>
<description>My description</description>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>main</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.59</version>
<scope>main</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
<scope>main</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.6</version>
<scope>main</scope>
</dependency>
<dependency>
<groupId>com.salesforce.seti</groupId>
<artifactId>selenium-dependencies</artifactId>
<version>1.0.3</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<packaging>pom</packaging>
</project>
我的项目文件夹结构是
.src
...main
.....java
.......projectname
.........constantsFolder
.........utilFolder
...........util1.java
...........util2.java
.........Test1.java
.........TestRunnerSuite.java
.........WebDrivers.java
如果我从Test1.java开始测试,尽管有警告,但测试仍会定期运行
[main] INFO projectname.util.util1 - Set up chrome driver.
Starting ChromeDriver 75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770@{#1003}) on port 28755
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1566609934.853][WARNING]: This version of ChromeDriver has not been tested with Chrome version 76.
Aug 23,2019 6:25:34 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[main] INFO projectname.util.util1 - Navigating to https://mytest.com/
但是,在添加如下的testSuiteRunner之后。
@RunWith(Suite.class)
@Suite.SuiteClasses({ Test1.class })
public class TestSuiteRunner {
public static void main(String[] args) {
Result result = JUnitCore.runClasses(Test1.class);
// print erros,exit etc omitted
}
}
现在,我收到了奇怪的错误,无法启动chromedriver。我拥有的Webdriver是Singleton
public class WebDrivers {
private static WebDriver driver = null;
public static WebDriver getInstance(){
if (driver == null) {
driver = new ChromeDriver();
}
return driver;
}
}
这是我第一次尝试从地面进行一切设置。我不确定是pom依赖问题,单例webdriver问题还是其他原因。谁能对此发表看法并提供一些线索?非常感激。
ruby – 如何在无头Chrome上使用Selenium Webdriver?
我已经能够使用’selenium-webdriver’宝石和chromedriver截取屏幕截图,但不是无头.
这是我正在运行的ruby脚本,它在开始初始化驱动程序后挂起
require 'rubygems' require 'selenium-webdriver' Selenium::WebDriver.logger.level = :debug p 'initializing driver' driver = Selenium::WebDriver.for :chrome,switches: %w[--headless --disable-gpu --screenshot --hide-scrollbars] p 'navigating to Google' driver.navigate.to "http://google.com" driver.save_screenshot("./screen.png") driver.quit
和日志的输出:
:> ruby rubytest.rb "initializing driver" 2017-06-07 15:55:43 DEBUG Selenium Executing Process ["/Users/name/Documents/scrapings/python/env/bin/chromedriver","--port=9515"] 2017-06-07 15:55:43 DEBUG Selenium polling for socket on ["127.0.0.1",9515] Starting ChromeDriver 2.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b) on port 9515 Only local connections are allowed. 2017-06-07 15:55:43 INFO Selenium -> POST session 2017-06-07 15:55:43 INFO Selenium >>> http://127.0.0.1:9515/session | {"desiredCapabilities":{"browserName":"chrome","version":"","platform":"ANY","javascriptEnabled":true,"cssSelectorsEnabled":true,"takesScreenshot":false,"nativeEvents":false,"rotatable":false,"chromeOptions":{"args":["--headless","--disable-gpu","--screenshot","--hide-scrollbars"]}}} 2017-06-07 15:55:43 DEBUG Selenium > {"Accept"=>"application/json","Content-Type"=>"application/json; charset=utf-8","Content-Length"=>"284"} [RUBY BACKTRACE TO DRIVER INITIALIZATION]
我尝试使用类似代码的JavaScript和Python驱动程序,没有任何作用.当我尝试使用Python时,错误消息是
WebDriverException: Message: unkNown error: Chrome Failed to start: exited abnormally (Driver info: chromedriver=2.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b),platform=Mac OS X 10.12.5 x86_64)
解决方法
require "selenium-webdriver" # configure the driver to run in headless mode options = Selenium::WebDriver::Chrome::Options.new options.add_argument('--headless') driver = Selenium::WebDriver.for :chrome,options: options driver.navigate.to "https://www.google.com" # resize the window and take a screenshot driver.manage.window.resize_to(800,800) driver.save_screenshot "screenshot.png"
关于我们如何在colab.research.google.com中使用Selenium Webdriver?和google colab怎么用的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于cucumber; Selenium WebDriver-如何使用Google Chrome浏览器代替Firefox作为测试浏览器、java – 如何用selenium webdriver发送cookies?、org.openqa.selenium.remote.service.DriverService $ Builder.createArgs()Lcom /google / common / collect / ImmutableList; 使用Selenium 3.5.3 Chrome 76、ruby – 如何在无头Chrome上使用Selenium Webdriver?等相关知识的信息别忘了在本站进行查找喔。
本文标签: