本文整理汇总了C#中OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScript方法的典型用法代码示例。如果您正苦于以下问题:C# RemoteWebDriver.ExecuteScript方法的具体用法?C# RemoteWebDriver.ExecuteScript怎么用?C# RemoteWebDriver.ExecuteScript使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Remote.RemoteWebDriver
的用法示例。
在下文中一共展示了RemoteWebDriver.ExecuteScript方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WaitUnitJavascriptTrue
private static void WaitUnitJavascriptTrue(RemoteWebDriver driver, string javascript)
{
Func<IWebDriver, bool> condition = delegate
{
var scriptResult = driver.ExecuteScript(javascript);
var isScriptActive = (bool)scriptResult;
return isScriptActive;
};
driver.Wait().Until(condition);
}
示例2: SmokeTestSetup
public void SmokeTestSetup()
{
driver = new FirefoxDriver();
_runner = new NzbDroneRunner(LogManager.GetCurrentClassLogger());
_runner.KillAll();
_runner.Start();
driver.Url = "http://localhost:8989";
var page = new PageBase(driver);
page.WaitForNoSpinner();
driver.ExecuteScript("window.NzbDrone.NameViews = true;");
GetPageErrors().Should().BeEmpty();
}
示例3: Connect
public bool Connect()
{
try
{
Dictionary<string, object> capsDef = new Dictionary<string, object>();
capsDef.Add("device", _Model.Settings.InspectorDeviceCapability.ToString());
ICapabilities capabilities = new DesiredCapabilities(capsDef);
_Driver = new ScreenshotRemoteWebDriver(new Uri("http://" + this._Model.IPAddress + ":" + this._Model.Port.ToString() + "/wd/hub"), capabilities);
// add increased timeout for inspector connection
Dictionary<string, int> args = new Dictionary<string, int>();
args.Add("timeout", 900);
_Driver.ExecuteScript("mobile: setCommandTimeout", new object[] { args });
}
catch (Exception e)
{
LastMessage = e.Message;
return false;
}
return true;
}
示例4: GetUserAgent
private string GetUserAgent(RemoteWebDriver driver)
{
return driver.ExecuteScript("return window.navigator.userAgent;").ToString();
}
示例5: ReportCapabilities
private static void ReportCapabilities(RemoteWebDriver driver)
{
Log.InfoFormat("Driver Capabilities: {0}", driver.Capabilities);
Log.InfoFormat("User agent: {0}", driver.ExecuteScript("return navigator.userAgent;"));
}
示例6: SaveHtmlAndScreenShot
private static void SaveHtmlAndScreenShot(Uri uri, RemoteWebDriver _driver)
{
try
{
var removeScriptTag =
"Array.prototype.slice.call(document.getElementsByTagName('script')).forEach(function(item) { item.parentNode.removeChild(item);});";
var addClassToBody = "document.getElementsByTagName('body')[0].className += ' seoPrerender';";
_driver.ExecuteScript(removeScriptTag + addClassToBody);
//uri.AbsolutePath is relative url
var result = _driver.PageSource;
string filenameWithPath = _options.FolderPath + uri.AbsolutePath + MakeValidFileName(uri.Query);
Directory.CreateDirectory(Path.GetDirectoryName(filenameWithPath));
File.WriteAllText(filenameWithPath + ".html", result);
logger.Info("SaveHtmlAndScreenShot to {0}.html", filenameWithPath);
_driver.GetScreenshot().SaveAsFile(filenameWithPath + ".jpg", ImageFormat.Jpeg);
}
catch (Exception ex)
{
logger.Error(ex);
}
}
示例7: SetDateValueForJQueryDatepicker
public static void SetDateValueForJQueryDatepicker(RemoteWebDriver browser, string elementSelector, DateTime value)
{
var formattedDate = value.ToString("d MMMM yyyy");
browser.FindElementByCssSelector(elementSelector);
browser.ExecuteScript("$(arguments[0]).datepicker('setDate', arguments[1]);", elementSelector, formattedDate);
}
示例8: BlockUntilElementIsAvailable
private void BlockUntilElementIsAvailable(RemoteWebDriver driver, string elementSelector)
{
while (true)
{
var len = driver.ExecuteScript("return $(\"" + elementSelector + "\").length");
if (Convert.ToInt32(len) > 0)
break;
Thread.Sleep(100);
}
}