gpt4 book ai didi

selenium - DesiredCapabilities 类型未定义方法 firefox()

转载 作者:行者123 更新时间:2023-11-28 21:37:07 44 4
gpt4 key购买 nike

我正在尝试在我的机器上运行 selenium 网格,并且正在为所有浏览器获取以下信息 cap = DesiredCapabilities.firefox();:DesiredCapabilities 类型未定义方法 firefox()

下面是我的代码

并行打包;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
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.Parameters;
import org.testng.annotations.Test;

public class GridTest {


public WebDriver driver=null;

@Parameters("browser") //testng.xml
@Test()
public void googleTest(String b) throws MalformedURLException, InterruptedException{

System.out.println("Google " + b);

DesiredCapabilities cap = null;

if(b.equals("firefox")){
cap = DesiredCapabilities.firefox();
cap.setBrowserName("firefox");
cap.setPlatform(Platform.ANY);
}else if (b.equals("chrome")){
cap = DesiredCapabilities.chrome();
cap.setBrowserName("chrome");
cap.setPlatform(Platform.ANY);
}else if (b.equals("iexplore")){
cap = DesiredCapabilities.internetExplorer();
cap.setBrowserName("iexplore");
cap.setPlatform(Platform.WINDOWS);
}

try{driver = new RemoteWebDriver(new URL("http://10.0.30.240:4446/wd/hub"),cap);
} catch (MalformedURLException e) {


driver.get("http://google.com");
driver.findElement(By.name("q")).sendKeys("Hello "+b);
Thread.sleep(2000);


driver.quit();

}}}

最佳答案

将 selenium 独立服务器添加到我的 pom.xml 解决了这个问题:

<!--  https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server-standalone -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.4.0</version>
</dependency>

关于selenium - DesiredCapabilities 类型未定义方法 firefox(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57279167/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com