有没有办法使用geckodriver使您的 Selenium 脚本在 Python 中无法检测到?
我正在使用 Selenium 进行抓取。我们是否需要使用任何保护措施使网站无法检测到 Selenium?
Selenium 3.0 Firefx驱动程序因org.openqa.selenium.SessionNotCreatedException而失败:无法创建新的远程会话.
System.setProperty("webdriver.gecko.driver", "..<Path>../geckodriver.exe");
capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions@23aa363a, browserName=firefox, moz:firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions@23aa363a, version=, platform=ANY}], required capabilities = Capabilities [{}]
Build info: version: '3.0.0', revision: '350cf60', time: '2016-10-13 10:48:57 -0700'
System info: host: 'D202540', ip: '10.22.19.193', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_45'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
at …Run Code Online (Sandbox Code Playgroud) 我正在开发一个基于java/selenium的应用程序,需要将媒体,即音频和/或视频文件传递给浏览器.
我已经能够使用以下代码段在Chrome中成功完成此操作:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("--allow-file-access-from-files",
"--use-fake-ui-for-media-stream",
"--allow-file-access",
"--use-file-for-fake-audio-capture=D:\\PATH\\TO\\WAV\\xxx.wav",
"--use-fake-device-for-media-stream");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
Run Code Online (Sandbox Code Playgroud)
Firefox 33.1中是否有类似的选项可以实现相同的功能?
如果没有,怎么办呢?
我想在新窗口中打开同一窗口中的所有链接.我试过了
profile.setPreference("browser.link.open_newwindow", 1)
Run Code Online (Sandbox Code Playgroud)
但结果是:
WARNING: traffic.loop 0 error: Preference browser.link.open_external may not be overridden: frozen value=2, requested value=1
Run Code Online (Sandbox Code Playgroud)
还有另一种方法可以在同一个窗口中打开链接吗?
有时在我使用Selenium 2.41进行测试并使用Firefox 28进行测试时,执行会等待页面加载.
这是等待条件:
int time = 30;
WebDriverWait wait = new WebDriverWait(webDriver, time);
ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
}
};
wait.until(pageLoadCondition);
Run Code Online (Sandbox Code Playgroud)
假设30秒后这个方法会抛出一个TimeoutException,但它不会,有时会永远挂起.这是在这些情况下产生的堆栈跟踪:
java.lang.Thread.State:java.net.SocketInputStream.socketRead0(本机方法)中的rUNNABLE,位于org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer)的java.net.SocketInputStream.read(未知源). java:160)org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:84)atg.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:273)at org.apache .http.impl.conn.LoggingSessionInputBuffer.readLine(LoggingSessionInputBuffer.java:116)org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)atg.apache.http.impl.conn.DefaultHttpResponseParser .parseHead(DefaultHttpResponseParser.java:57)在org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)在org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:283)在org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHead ER(DefaultClientConnection.java:251)在org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:223)在org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)在组织.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)在org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:682)在org.apache.http.impl.client.DefaultRequestDirector .execute(DefaultRequestDirector.java:486)在org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)在org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72 )在org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)在org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:322)在org.openqa.selenium.remote.在org.openqa.selenium.fir的HttpCommandExecutor.execute(HttpCommandExecutor.java:301)efox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165)org.openqa.selenium.firefox.FirefoxDriver $ LazyCommandExecutor.execute(FirefoxDriver.java:362)org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver. Java的:568)在org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:504)维持在es.tao es.tao.commonservices.selenium.tests.TAORobotWebDriver $ 1.适用(TAORobotWebDriver.java:6227). commonservices.selenium.tests.TAORobotWebDriver $ 1.apply(TAORobotWebDriver.java:1)at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)at es.tao.commonservices.selenium.tests.TAORobotWebDriver .waitToLoad(TAORobotWebDriver.java:6230)at es.tao.commonservices.selenium.tests.TAORobotWebDriver.handleWaitToLoad(TAORobotWebDriver.java:6110)
我已经为firefox配置文件设置了这个首选项,但它仍然无法正常工作:
ffProfile = new FirefoxProfile();
ffProfile.setPreference("webdriver.load.strategy", "unstable");
Run Code Online (Sandbox Code Playgroud)
也有这个属性设置:
webDriver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
webDriver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
Run Code Online (Sandbox Code Playgroud) 我已经升级到 Selenium 4
new_binary_path = FirefoxBinary('path_to_binary')
selenium.webdriver.Firefox(executable_path=path, options=ops, firefox_binary=new_binary_path)
Run Code Online (Sandbox Code Playgroud)
或者
options.add_argument("--setBinary(path_to_binary)")
selenium.webdriver.Firefox(executable_path=path, options=ops)
Run Code Online (Sandbox Code Playgroud)
返回此错误信息
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
Run Code Online (Sandbox Code Playgroud)
文档
https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/CHANGES.md
说
删除了 firefox.Binary 类。仍然可以使用 firefox.Options#setBinary() 选择自定义二进制文件。同样,可以使用 firefox.Options#addArguments() 指定自定义二进制参数
有谁知道如何实施这些更改?我不知道标签是什么意思。我尝试过options.setBinary()但setBinary()没有被识别。
我有这段代码可以工作并加载 Firefox 配置文件
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
ffOptions = Options()
ffProfile = FirefoxProfile(r'C:\Users\Tyler\AppData\Roaming\Mozilla\Firefox\Profiles\0753x1pz.default')
ffOptions.profile = ffProfile
driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")
Run Code Online (Sandbox Code Playgroud)
仅它给出以下弃用警告:
firefox_profile 已被弃用,请使用 Options 对象
设置配置文件已被弃用。请使用 set_preference 和 install_addons 方法
为了解决警告,我尝试将代码更新为
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
ffOptions = Options()
ffOptions.set_preference('profile', r'C:\Users\Tyler\AppData\Roaming\Mozilla\Firefox\Profiles\0753x1pz.default')
driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")
Run Code Online (Sandbox Code Playgroud)
现在没有警告,但浏览器打开时未设置配置文件,它是一个空白配置文件。
selenium python-3.x selenium-firefoxdriver firefox-profile selenium4
我正在使用selenium 2.24 firefox驱动程序来测试输入框的模糊事件.目前在我将Keys发送到输入框之后,我让selenium点击另一个区域来触发输入框模糊,但是我认为这不是一个好方法,任何人都知道更好的测试方法吗?
非常感谢.
我尝试使用新的geckodriver,为FF48和selenium 3打开牵线木偶,但测试无法在下拉列表中为任何元素选择选项.我的测试在FF45和所有其他浏览器中都能正常工作.只有牵线木偶驱动程序不会在下拉列表中选择该选项
new Select(driver.findElement(By.Id("topic"))).selectByVisibleText(item);
Run Code Online (Sandbox Code Playgroud)
代码工作正常,直到我开始使用gecko驱动程序与木偶.
下面是我用来设置带木偶的geckodriver的代码.
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("DefaultProfile");
myprofile.setPreference("network.proxy.type", ProxyType.AUTODETECT.ordinal());
DesiredCapabilities dc=DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, myprofile);
dc.setCapability("marionette", true);
driver = new FirefoxDriver(dc);
Run Code Online (Sandbox Code Playgroud)
当尝试从元素中选择一个选项时,测试不会抛出任何异常.
new Select(driver.findElement(By.Id("topic"))).selectByVisibleText(item);
Run Code Online (Sandbox Code Playgroud)
在研究了这个问题之后,结果发现FF48有一个bug并且它已经在firefox中修复了51.在等待FF51发布的时候,是否有任何解决方法使它在FF48中工作?
firefox webdriver selenium-firefoxdriver selenium-webdriver geckodriver
尝试在登录期间使用send_keys()方法输入用户名.我想它能够找到输入元素,就像我跑到send_keys它工作之前一样.通过发送字符串值send_keys,它会引发错误.
selenium.common.exceptions.WebDriverException:消息:预期[对象未定义]未定义为字符串
我错过了什么?
Python:3.5
Selenium 3.3.1
Firefox Developer Edition或Nightly(当前版本> 52)
我的代码片段:
login_url = "https://korunet.co.nz/"
driver = webdriver.Firefox()
driver.get(login_url)
WebDriverWait(driver, 30).until(ec.visibility_of_element_located((By.CSS_SELECTOR, '#IDToken1')))
elem = driver.find_element_by_css_selector('#IDToken1')
elem.click()
elem.clear()
elem.send_keys("10101")
Run Code Online (Sandbox Code Playgroud)
Traceback(最近一次调用最后一次):
文件"D:/PycharmProjects/JCBbidEntry/tests/loop2.py",第29行,在elem.send_keys("10101")
文件"C:\ Users\BaruaR\AppData\Roaming\Python\Python35\site-packages\selenium\webdriver\remote\webelement.py",第347行,在send_keys中自我._execute(Command.SEND_KEYS_TO_ELEMENT,{'value':keys_to_typing(value)})
文件"C:\ Users\BaruaR\AppData\Roaming\Python\Python35\site-packages\selenium\webdriver\remote\webelement.py",第491行,在_execute中返回self._parent.execute(command,params)
文件"C:\ Users\BaruaR\AppData\Roaming\Python\Python35\site -packages\selenium\webdriver\remote\webdriver.py",第238行,执行self.error_handler.check_response(响应)
文件"C:\ Users\BaruaR\AppData\Roaming\Python\Python35\site-packages\selenium\webdriver\remote\errorhandler.py",第193行,在check_response中
引发exception_class(消息,屏幕,堆栈跟踪)
python-3.x selenium-firefoxdriver selenium-webdriver geckodriver
selenium ×7
firefox ×5
geckodriver ×5
python-3.x ×3
webdriver ×2
java ×1
python ×1
selenium4 ×1