【发布时间】:2015-05-17 18:29:30
【问题描述】:
我正在学习使用Selenium WebDriver(最新版本)读取javascript 变量。有时它有效,有时无效。以下是我在 whoscored.com 上的尝试,它一直显示错误
using (IWebDriver driver = new ChromeDriver())
{
driver.Navigate().GoToUrl("http://www.whoscored.com/Regions/81/Tournaments/3/Germany-Bundesliga");
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
var tournament = wait.Until(ExpectedConditions.ElementExists(By.Id("tournament-fixture-wrapper")));
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
var obj = (object)js.ExecuteScript("return window.allRegions;"); //always return error 'Additional information: Unable to cast object of type 'System.Int64' to type 'System.String'.
}
【问题讨论】:
-
还有,你想读的 JavaScript 是什么?你能提供吗?
-
它在链接中whoscored.com/Regions/81/Tournaments/3/Germany-Bundesliga var allRegions = [{type:1, id:248, flg:'flg-caf', name: 'Africa', 锦标赛: [{id:290, url:'/Regions/248/Tournaments/290/Africa-CAF-Champions-League', name:'CAF Champions League'},{id:573, url:'/Regions/248/Tournaments/573/Africa-' , name:''},...抱歉,这里粘贴太长了
标签: javascript c# selenium selenium-webdriver webdriver