以下选项不起作用。 在 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/