这听起来像你现在正在使用遥控器设置,是吗?您应该能够从该代码中实例化WebDriver实例,但您需要引用WebDriver dll。您需要实例化浏览器驱动程序对象的实例(即:FirefoxDriver,InternetExplorerDriver,ChromeDriver等),然后将您的IWebDriver“驱动程序”属性设置为与该实例相同。然后创建一个名为“js”(或任何你想要的)的接口对象作为IJavaScriptExecutor对象,并调用非静态方法“ExecuteScript”或“ExecuteAsyncScript”(在你的情况下)。
我的代码在C#.NET中(假设你使用的是NUnit)。因为我不知道这种语言,所以你必须找到Python的实现。
类的数据成员:
private IWebDriver driver;
private StringBuilder verificationErrors;
private string baseURL;
代码:
driver = new FirefoxDriver(new FirefoxProfile());
baseURL = "http://???"; // replace "???" with website domain
ISelenium selenium = new WebDriverBackedSelenium(driver, baseURL);
selenium.Start();
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.ExecuteScript("$('#id').click();"); // assumes JQuery is used in page
js.ExecuteAsyncScript(...);