簡體   English   中英

無法在 C# 中使用 Selenium WebDriver 執行 JavaScript 命令

[英]Can not Execute JavaScript command using Selenium WebDriver in C#

我無法使用 selenium Web 驅動程序執行 js 命令。 例如,我對這個 URL 使用了 3 種方式,但它們都返回 null。

                    web.FindElementByJs("StackExchange.init.length");

                    IJavaScriptExecutor js = (IJavaScriptExecutor)web;
                    string title = (string)js.ExecuteScript("StackExchange.init.length");

                    web.ExecuteJavaScript("StackExchange.init.length");

我得到它! 對於對象,我應該使用“窗口”。

IJavaScriptExecutor js = (IJavaScriptExecutor)web;
string title = (string)js.ExecuteScript("return window.StackExchange.init.length");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM