使用 Chrome (chromedriver) 非常简单:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_experimental_option('detach', True)
Run Code Online (Sandbox Code Playgroud)
使用 Firefox (geckodriver) 则不会:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_experimental_option('detach', True) # Returns syntax error
Run Code Online (Sandbox Code Playgroud)
即使脚本结束也保持 Firefox 浏览器打开的等效语法是什么?
我正在尝试用 python 中的这个简单程序打开 Firefox,我使用的是最新版本的 Ubuntu。
from selenium import webdriver
brow = webdriver.Firefox()
Run Code Online (Sandbox Code Playgroud)
但我收到错误消息“selenium.common.exceptions.SessionNotCreatedException:消息:无法启动浏览器/snap/firefox/current/firefox.launcher:没有这样的文件或目录”
我尝试更新 Firefox 并使用不同的 geckodriver。
我正在遵循使用python学习TDD的指南。在某些时候,在进行迁移后,命令的输出python3 functional_tests.py应该是(根据本书):
self.fail('Finish the test!')
AssertionError: Finish the test!
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
selenium.common.exceptions.InvalidSelectorException: Message: Given css selector expression "tr" is invalid: TypeError: can't access dead object
Run Code Online (Sandbox Code Playgroud)
在尝试第二次(以及更多次)之后:
selenium.common.exceptions.StaleElementReferenceException: Message: The element reference is stale. Either the element is no longer attached to the DOM or the page has been refreshed.
Run Code Online (Sandbox Code Playgroud)
我一直在谷歌搜索并搜索类似的问题,但没有找到可以帮助我解决问题的问题。
我正在使用 geckodriver,并将它的路径添加到PATH.
Django==1.8.7
selenium==3.0.2
Mozilla Firefox 50.0.2
(X)Ubuntu 16.04
Run Code Online (Sandbox Code Playgroud)
我应该切换到 Chrome 吗?这不是微不足道的,它需要我一些时间,但它可以工作吗?更像 Firefox 还是 Selenium?我认为这与代码无关 - 我为第 5 章克隆了repo,并且发生了同样的崩溃。
python 代码无法找到 geckodriver 。
import time
from selenium import webdriver
browser=webdriver.Firefox('D:/Folder_1/chrome_driver/geckodriver_win32/geckodriver.exe')
Run Code Online (Sandbox Code Playgroud)
错误:WindowsError:[错误 267] 目录名无效:'D:/Folder_1/chrome_driver/geckodriver_win32/geckodriver.exe/ 。'
我无法让Selenium与c#上的Firefox驱动程序一起使用。Chrome可以完美运行,但Firefox无法运行。
使用方法:
我已经在Windows中设置了path变量。
GeckoDriver已安装在源代码的Bin文件夹中。
Firefoxdriverservice不存在,因此无法使用该命令。
我收到的错误是“ 引发异常:System.ComponentModel.Win32Exception:系统找不到指定的文件 ”
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System.Windows.Forms;
namespace BeatRecaptcha
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
IWebDriver driver = new FirefoxDriver();
driver.Manage().Window.Maximize();
//Go to Google
driver.Navigate().GoToUrl("www.google.co.uk");
}
}
Run Code Online (Sandbox Code Playgroud)
}
我正在尝试使用Firefox geckodriver 和aShot Library水平和垂直拍摄完整的页面截图。
然而,结果并不如预期。看一看:
driver.get("https://google.com");
Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
ImageIO.write(fpScreenshot.getImage(),"JPEG",new File("FullPageScreenshot.jpg"));
Run Code Online (Sandbox Code Playgroud)
研究了很多变体,但没有任何效果。有趣的是,当我尝试使用旧的 Firefox 版本 (46) 时,我可以在没有任何第三方库的情况下截取完整的屏幕截图。我正在尝试使用最新的 Firefox 并具有完整的屏幕截图功能。
有什么帮助吗?
我有以下代码:
options = Options()
options = options.set_headless( headless=True)
class Sel_Driver():
def __init__(self):
self.driver = webdriver.Firefox(firefox_options=options)
Run Code Online (Sandbox Code Playgroud)
然后,我可以将其self.driver.get(url)用作方法的一部分来打开我输入的 URL。这有效 - 我可以输入并打开 URL,但它们不在无头模式下。
(我最初将驱动程序定义为self.driver = webdriver.Firefox(firefox_options=Options().set_headless(headless=True)- 但这不起作用,所以我如上所述尝试了它)。
我错过了什么?我不明白为什么驱动程序能够打开页面,但选项未启用。
当我运行我的selenium代码时,我收到错误"错误:找到参数'--webdriver-port'这是不期望的,或者在此上下文中无效"
我正在使用Firefox 48.0使用gecko驱动程序我已经初始化了浏览器.并得到上述错误.
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class NewGmail {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
String url = "https://accounts.google.com/signin";
driver.get(url);
driver.findElement(By.id("identifierId")).sendKeys("cp8805");
//driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebDriverWait wait=new WebDriverWait(driver, 20);
driver.findElement(By.xpath("//span[@class='RveJvd snByac']")).click();
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
driver.findElement(By.xpath("//input[@class='whsOnd zHQkBf']")).sendKeys("xxxxxx");
driver.findElement(By.xpath("//span[@class='RveJvd snByac']")).click();
}
}
Run Code Online (Sandbox Code Playgroud)
在邮件ID之后我的密码也写在id框选项中,服务器重定向到下一个密码页面.我想问一下我将做什么,以便我的密码只能输入密码页面.