我正在尝试使用Selenium Webdriver在IE11上运行一些自动化测试。每当我运行我的代码时,IE尝试加载的URL为http://--port=38198/
我正在尝试简单地加载Google并返回标题,然后我将进入我打算进行的实际自动化测试。 以下是我目前的代码示例;
private WebDriver driver;
private String baseUrl;
@Before
public void setUp() throws Exception{
System.setProperty("webdriver.ie.driver", "C:\\Program Files\\Internet Explorer\\iexplore.exe");
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
baseUrl = "http//www.google.com";
driver = new InternetExplorerDriver(cap);
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void test() throws Exception{
driver.get(baseUrl);
System.out.println(driver.getTitle());
//driver.navigate().to(baseUrl);
}
我经常运行代码时始终会打开相同的网址 - http://--port=
从我的代码我不知道我哪里出错了。我将IE上的安全设置更改为中等和禁用保护模式(我已尝试打开保护模式但仍然没有运气)。我还下载并安装了Microsofts IE11网络驱动程序。
我对此完全不知所措,有人能给我任何见解......
答案 0 :(得分:1)
您似乎正在使用原生Windows IE?
您必须从https://code.google.com/p/selenium/wiki/InternetExplorerDriver下载IE WebDriver,并且您的using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class WebPages_testchart : System.Web.UI.Page
{
[WebMethod]
public static string GetChart()
{
string constr = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
string query = string.Format(@"select 'saudi','11.15' union all
select 'venezuela','2.5' union all
select 'canada','3.6' union all
select 'Iran','4.2' union all
select 'Iraq','2.6'");
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = query;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
StringBuilder sb = new StringBuilder();
sb.Append("[");
while (sdr.Read())
{
sb.Append("{");
sb.Append(string.Format("label :'{1}', y:'{0}'", sdr[0], sdr[1]));
sb.Append("},");
}
sb = sb.Remove(sb.Length - 1, 1);
sb.Append("]");
con.Close();
return sb.ToString();
}
}
}
}
}
媒体资源需要指向已下载的webdriver.ie.driver
请尝试报告是否能解决您的问题。如果没有,我会将我的chrome WebDriver更改为IE并自己尝试:)