javascript - 如何使用 selenium Web 驱动程序或使用 Javascript 防止页面重新加载?

标签 javascript c# selenium selenium-webdriver webdriver

以下选项不起作用。 在 selenium c# 或使用 JavaScript 中还有其他选项可以尝试吗?

尝试了以下语句,但仍然没有成功。 driver.findElement(By.tagName("body")).sendKeys("Keys.ESCAPE");driver.execute_script("window.stop();")

driver.findElement(By.tagName("body")).sendKeys("Keys.ESCAPE");driver.execute_script("window.stop();")

想要停止重新加载网页。

最佳答案

停止()

Window stop() Method停止窗口加载,与单击浏览器的停止按钮相同。

<小时/>

用法示例

  • Python:

    driver.execute_script("window.stop();");
    
  • Java:

    ((JavascriptExecutor)driver).executeScript("window.stop();");
    
  • C#:

    ((IJavaScriptExecutor)driver).ExecuteScript("window.stop();");
    

Note: Because of the script execution, this method cannot interrupt its parent document's loading, but it will stop its images, new windows, and other still-loading objects.

关于javascript - 如何使用 selenium Web 驱动程序或使用 Javascript 防止页面重新加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57992251/

相关文章:

ruby-on-rails-4 - 使用 Rails 4 的 cucumber 测试抛出错误 : element is not attached to the page document

c# - 搜索查询中的引号错误

java - 如何在不使用 jenkins 的情况下在 AWS 中运行本地 Selenium 测试脚本

javascript - javascript 或 jQuery 中的 $.expr [":"] 是什么?

javascript - 对多个数组中的公共(public)值进行分组

c# - 更改 Crystal Reports 查看器连接字符串 ASP.NET

c# - Windows 服务等待处理停止请求的最长时间是多少以及如何请求额外的时间

python - 如何在不实例化新驱动程序的情况下使用 Selenium 切换 Firefox 配置文件?

javascript - window.location 和 document.location 有什么区别?

javascript - Android 脚本层 - LibGDX