[英]Unable to start Internet Explorer or Chrome in Selenium Webdriver (JAVA)
I am trying to start up an IE instance using Webdriver. 我正在尝试使用Webdriver启动IE实例。 I can't figure out why I'm receiving these errors, my code appears to be identical to every example I can find on the web.
我不知道为什么会收到这些错误,我的代码似乎与我在网上可以找到的每个示例相同。
I'm using Java and testng. 我正在使用Java和testng。
Here is the code: 这是代码:
import java.io.File;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.WebDriver;
public class Tests {
File file = new File("C:\\selenium\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath() );
WebDriver driver = new InternetExplorerDriver();
}
The following errors are displaying, all of these errors are on the "System.setProperty" line. 正在显示以下错误,所有这些错误都在“ System.setProperty”行上。
Multiple markers at this line - Syntax error on token ""webdriver.ie.driver"", invalid FormalParameterList - Syntax error on token(s), misplaced construct(s) - Syntax error on tokens, FormalParameter expected instead 此行上有多个标记-令牌““ webdriver.ie.driver”“上的语法错误,无效的FormalParameterList-令牌上的语法错误,结构放置错误-令牌上的语法错误,应使用FormalParameter
Please note that I have the exact same problem if I try to use Chrome with this code: 请注意,如果我尝试将Chrome与以下代码结合使用,则会遇到完全相同的问题:
File file = new File("C:/selenium/chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
WebDriver driver = new ChromeDriver();
You are running your code from inside class instead of running it from inside method. 您从类内部运行代码,而不是从内部方法运行代码。 Covert it to something like
隐瞒它像
import java.io.File;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.WebDriver;
public class Tests {
public static void main(String[] args) { // <-- you need a method!
File file = new File("C:\\selenium\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath() );
WebDriver driver = new InternetExplorerDriver();
}
}
try this : 尝试这个 :
I'm using "mvn test" to lunch the test process so the path of the IE driver may be changed 我正在使用“ MVN测试”来测试过程,所以IE驱动程序的路径可能会更改
File file = new File("classes/tools/IEDriverServer.exe");
Use IE driver with Capabilities 使用具有功能的IE驱动程序
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
caps.setCapability("ignoreZoomSetting", true);
caps.setCapability("nativeEvents", false);
WebDriver driver = new InternetExplorerDriver(caps);
It may help you :) 它可能会帮助您:)
Actually, on the updated eclipse version, you might have to use @suppressWarnings 实际上,在更新的Eclipse版本上,您可能必须使用@suppressWarnings
package Login;
import java.io.File;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.WebDriver;
public class Login {
public static void main(String[] args) {
File file = new File("C:\\Users\\IEDRiverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath() );
@SuppressWarnings("unused")
WebDriver driver = new InternetExplorerDriver();
}
}
Simple example: 简单的例子:
public class IE {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.ie.driver", "D:\\Sathish\\soft\\SELENIUM\\LatestDownloads\\selenium\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("www.google.com");
driver.findElement(By.id("gbqfq")).sendKeys("abc");
driver.close();
}
}
Do the below process. 请执行以下过程。
import org.openqa.selenium.ie.InternetExplorerDriver; 导入org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities; 导入org.openqa.selenium.remote.DesiredCapabilities;
if (browserName.equalsIgnoreCase("InternetExplorer")) { 如果(browserName.equalsIgnoreCase(“ InternetExplorer”)){
DesiredCapabilities caps = DesiredCapabilities.internetExplorer(); DesiredCapabilities上限= DesiredCapabilities.internetExplorer();
System.setProperty("webdriver.ie.driver", "drivers/IEDriverServer.exe"); System.setProperty(“ webdriver.ie.driver”,“ drivers / IEDriverServer.exe”); caps.setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
caps.setCapability("nativeEvents", false); caps.setCapability(“ nativeEvents”,false); browser = new InternetExplorerDriver(caps);
浏览器=新的InternetExplorerDriver(caps);
Then after, In IE, from the Tools menu (or the gear icon in the toolbar in later versions), select "Internet options." 然后,在IE中,从“工具”菜单(或更高版本的工具栏中的齿轮图标)中,选择“ Internet选项”。 Go to the Security tab.
转到“安全性”选项卡。 At the bottom of the dialog for each zone, you should see a check box labeled "Enable Protected Mode."
在每个区域的对话框底部,您应该看到一个标记为“启用保护模式”的复选框。 Set the value of the check box to the same value, either checked or unchecked, for each zone.
对于每个区域,将复选框的值设置为相同的值(选中或未选中)。
I have applied the same thing at my end, it works fine. 我在结束时应用了同样的东西,效果很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.