我使用Selenium 2.35.0并配置代理设置,如:
DesiredCapabilities cap = new DesiredCapabilities();
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(proxyStr).setFtpProxy(proxyStr).setSslProxy(proxyStr);
cap.setCapability(CapabilityType.PROXY, proxy);
driver = new FirefoxDriver(firefox, profile, cap);
Run Code Online (Sandbox Code Playgroud)
当我需要更改代理设置时,我强制重启webdriver并编写其他"proxyStr".
如何在没有webdriver重启的情况下实现这种变化?
使用时new FirefoxDriver()我总是得到一个
NoSuchMethodError:org.apache.xpath.XPathContext
(org.apache.xpath中org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:115)中的线程"main"java.lang.NoSuchMethodError:org.apache.xpath.XPathContext.(Z)V中的异常位于org.openqa.selenium.firefox.internal.FileExtension.readIdFromInstallRdf(FileExtension.java)的org.apache.xpath.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:184)中的.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:99) :120)org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:60)org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:63)org.openqa. orlen.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:442)中的selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:464)位于org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection. java:79)在org.openqa.sel的org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:250)enium.remote.RemoteWebDriver.(RemoteWebDriver.java:110)org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:195)org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:190)at at test.PerfTest.main上的org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:107)(PerfTest.java:35))
selenium xpath nosuchmethoderror selenium-firefoxdriver selenium-webdriver
我有WebDriver 2.41和Firefox 28,当我的测试创建FirefoxDriver实例时,我在控制台中看到以下字符串:
*** LOG addons.manager: Application has been upgraded
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: checkForChanges
.................
Run Code Online (Sandbox Code Playgroud)
我怎么能关掉这个日志?
这是遇到的“魔术”的处理方法:该代码在Ubuntu 16.04,Ubuntu 15.10上可以正常工作,但有错误:
org.openqa.selenium.WebDriverException: Error: Permission denied to access property "navigator"
org.openqa.selenium.WebDriverException: Error: Permission denied to access property "document"
Run Code Online (Sandbox Code Playgroud)
我有以下代码:
import geb.spock.GebReportingSpec
import geb.waiting.WaitTimeoutException
class LoginSpec extends GebReportingSpec {
def "#0 go to login FB"() {
when:
browser.go("https://www.facebook.com/")
then:
delay(9)
if (browser.title != "Facebook") {
browser.title == "Facebook - Log In or Sign Up"
browser.currentUrl == "https://www.facebook.com/"
waitFor(30){
$("#loginbutton").size() == 1
}
$("#email").value(Config.FB_USERNAME)
$("#pass").value(Config.FB_PASSWORD)
println("entered credentials")
$("#loginbutton").click()
}
delay(9)
}
void delay(Long seconds){
try {
waitFor(seconds){ }
} catch (WaitTimeoutException …Run Code Online (Sandbox Code Playgroud) firefox selenium selenium-firefoxdriver selenium-webdriver geckodriver
我需要一种自动化的方法来在Firefox Selenium Webdriver中启用Flash,而无需用户交互。
我试过了:
FirefoxProfile profile = new FirefoxProfile();
//As 0 is to disable, I used 1. I don"t know what to use.
profile.setPreference("plugin.state.flash", 1);
WebDriver driver = new FirefoxDriver(profile);
Run Code Online (Sandbox Code Playgroud)
但这仍然需要我单击“允许”。
java selenium webdriver selenium-firefoxdriver firefox-driver
我想在selenium自动化中以给定语言启动firefox浏览器.我能这样做吗?如果是这样,请分享一些示例代码实现.
提前致谢.
我正在使用 python 3.7 + selenium + geckodriver.exe + firefox 70.0.1x64,我知道driver.quit()可以关闭firefox窗口,但在某些情况下我无法完全退出firefox,我不知道为什么,这是我的代码:
from selenium import webdriver
import time
def func1():
driver = webdriver.Firefox()
i = 0
while True:
try:
if i > 10 and driver is not None:
driver.quit()
driver = None
print('quit success')
i += 1
print(i)
time.sleep(1)
except KeyboardInterrupt:
if driver is not None:
driver.quit()
driver = None
print('keyboard quit success')
if __name__ == '__main__':
func1()
Run Code Online (Sandbox Code Playgroud)
通过这段代码,有两种方法可以关闭 Firefox 窗口:
1-等待 10 秒。
2-使用 Ctrl+C。
然后我测试方法1
python test1.py
Run Code Online (Sandbox Code Playgroud)
当firefox …
在 Firefox 版本 97 和 98 中,当我在 iframe 内切换并截取屏幕截图时,出现异常: org.openqa.selenium.WebDriverException: SecurityError: Permission returned to access property pageXOffset" on cross-origin object。
方法中出现异常: org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs
我能够在 iFrame 内执行单击、getText 和所有其他操作。唯一的例外是在截图时出现
Chrome 99 中不会出现此类问题。
我尝试设置首选项:
profile.setPreference("browser.tabs.remote.useCrossOriginEmbedderPolicy", false);
profile.setPreference("security.csp.enable", false);
profile.setPreference("security.external_protocol_requires_permission", false);
profile.setPreference("security.fileuri.strict_origin_policy", false);
profile.setPreference("browser.tabs.remote.useCrossOriginOpenerPolicy", false);
profile.setPreference("network.http.referer.disallowCrossSiteRelaxingDefault.pbmode", false);
profile.setPreference("dom.block_external_protocol_in_iframes", false);
profile.setPreference("dom.block_download_in_sandboxed_iframes", false);
profile.setPreference("dom.delay.block_external_protocol_in_iframes.enabled", false);
profile.setPreference("dom.block_download_in_sandboxed_iframes", false);
Run Code Online (Sandbox Code Playgroud)
它不起作用。
但是,当我切换到主要内容并截取屏幕截图时,没有例外,但我的整个网页都在 iFrame 内,因此我必须在 iFrame 内切换并截取整个页面的多个屏幕截图。最近有人在 Firefox 中遇到过这个问题吗?请帮忙。
我正在使用 Selenium 版本:3.14.0 并使用 WebdriverManager 进行自动驱动程序下载。
如果我可以添加更多信息,请告诉我。
selenium selenium-firefoxdriver selenium-webdriver geckodriver
Selenium 与 DOM 的交互似乎非常慢,同时在每个页面实例化中做几件事。在整个站点中,我们都有可见的微调器,指示是否已解决任何未解决的 API 调用。总之,我有三种方法可以在执行任何操作之前确保页面的稳定性。
所有这三个都是通过以下方法作为页面对象实例化的一部分完成的。
public static void waitForLoadingAllSpinnersAnywhere(final WebDriver driver){
final WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(waitForDomReadyState());
wait.until(waitForjQueryToBeInactive());
List<WebElement> elements = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(spinnersLoacator));
for(WebElement element: elements){
wait.until(invisibilityOfElementLocated(element));
}
}
private static ExpectedCondition<Boolean> waitForDomReadyState(){
return new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver d){
return ( ((JavascriptExecutor) d).executeScript("return document.readyState;").equals("complete"));
}
};
}
private static ExpectedCondition<Boolean> waitForjQueryToBeInactive(){
return new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver d){
return (Boolean) ( ((JavascriptExecutor) d).executeScript("return jQuery.active == …Run Code Online (Sandbox Code Playgroud) selenium webdriver selenium-firefoxdriver selenium-webdriver firefox-driver
我正在编写一个程序来帮助我的客户从网站下载发票 PDF,我第一次使用drv.Navigate().GoToUrl(URL);. 之后程序休眠一段时间,当清醒时开始搜索我客户的电子邮件(使用S22 DLL),如果他找到某个电子邮件,则从电子邮件中提取链接并使用(第二次)drv.Navigate().GoToUrl(URL);。但这次我得到了一个例外
浏览上下文已被丢弃
我已经尝试了所有可能的方法,但最“令人震惊”的是我在 Google 上找不到关于此错误的任何信息,也没有在 Selenium 文档中找到任何信息。
我不明白什么意思
我确定链接有效,因为是同一个链接。
受此问题影响的代码下方
PS:第一次下载与第二次下载完全一样。
public static int Go(string URL, ImapClient EmailClient, uint mUID, bool isFromOutlook) {
// While the Firefox driver isn't initialized, wait for it
while (isDrvInit != 1 && isDrvInit != 2)
Thread.Sleep(1);
// If the Firefox driver was not able to initialize, we can't procede further
if (isDrvInit == 2)
return 0;
try {
drv.Navigate().GoToUrl(URL); // Here the program throw …Run Code Online (Sandbox Code Playgroud)