[英]JS Script to go back to previous page using webdriver doesnt work
My code spinet is as follow: 我的代码清单如下:
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.history.go(-1);");
The above code doest work please suggest. 上面的代码不起作用,请提出建议。 I tried above code by casting webdriver instant but did not work every time I don't want to use driver.navigate().back()
command as it not recommended. 我通过强制转换webdriver即时尝试了上面的代码,但是由于我不建议每次都不想使用driver.navigate().back()
命令,因此无法正常工作。 Please suggest... 请建议...
I am not sure why you are not using driver.navigate().back()
. 我不确定为什么不使用driver.navigate().back()
。 It's the recommended one. 这是推荐的。 Anyways, below is the way to do in javascript: 无论如何,以下是使用javascript的方法:
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("window.history.back();");
Note: Might require a sleep time of 2-3 seconds. 注意:可能需要2-3秒的睡眠时间。 But, it works, nonetheless. 但是,它仍然有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.