在Selenium Grid中我试图执行一个简单的程序,Cannot find firefox binary in PATH
虽然我已经在我的代码中添加了二进制路径.
我的代码和错误如下.请帮忙.提前致谢.
码
package Sample;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class sample1 {
WebDriver driver;
String BaseURL,NodeURL;
@BeforeTest
public void beforeTest() throws MalformedURLException {
BaseURL="www.google.com";
NodeURL="http://192.168.10.162:5566/wd/hub";
DesiredCapabilities capa =DesiredCapabilities.firefox();
capa.setBrowserName("firefox");
capa.setCapability("binary", "C:\\Users\\praveenraj.d\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
capa.setPlatform(Platform.ANY);
driver=new RemoteWebDriver(new URL(NodeURL),capa);
}
@Test
public void f() throws InterruptedException {
driver.get(BaseURL);
System.out.println(driver.getTitle());
Thread.sleep(50000);
}
@AfterTest
public void afterTest() {
driver.quit();
}
}
Run Code Online (Sandbox Code Playgroud)
错误 …
当我尝试在 Selenium 中创建 Firefox 实例时,出现以下错误:
Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
Run Code Online (Sandbox Code Playgroud)
我在 Ubuntu 20.04 上运行
任何建议将不胜感激。
browser = webdriver.Firefox()
Traceback (most recent call last):
File "key.py", line 10, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", …
Run Code Online (Sandbox Code Playgroud) from selenium import webdriver;
browser= webdriver.Firefox();
browser.get('http://www.seleniumhq.org');
Run Code Online (Sandbox Code Playgroud)
当我尝试运行此代码时,它给了我一个error message
:
Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line.
Run Code Online (Sandbox Code Playgroud)
任何想法 - 高度赞赏!
我想在带有 Selenium Python 包的 Google Colaboratory 中使用 geckodriver。这是我尝试过的(我不是 Ubuntu 专家)
!pip install selenium
!apt-get update
!apt install firefox-geckodriver
from selenium.webdriver.firefox.options import Options as FirefoxOptions
firefox_options = FirefoxOptions()
firefox_options.add_argument("--headless")
driver = webdriver.Firefox(executable_path=r'/usr/bin/firefox', options=firefox_options)
Run Code Online (Sandbox Code Playgroud)
这里r'/usr/bin/firefox
是错误的。我糊涂了。解决办法是什么?任何帮助表示赞赏。
firefox python-3.x selenium-webdriver geckodriver google-colaboratory