如何在点击()后在 Chrome 上无需等待页面加载即运行下一行代码?

huangapple go评论142阅读模式
英文:

How to run the next line of code without waiting for page to load after click () java selenium on Chrome?

问题

加载页面后,我将使用 click() 方法点击一个元素。一旦执行了点击操作,我希望紧接着执行下一个命令。我该如何实现这个?

我有两种情况:

  1. 下一行命令与页面加载无关。
  2. 页面需要继续加载。

示例:

Driver.findElementBy("SignIn").click();
System.out.println("Random Done");

在点击之后,页面需要30-40秒来加载。因此,我希望在执行点击操作后立即显示输出 "Random Done",而不必等待那30-40秒。

大约一分钟后,我将会手动执行加载后页面的操作。

*希望我没有让你困惑。

英文:

After a page is loaded, I will click() an element. Once the click is performed, I want the next command to be performed. How can I do that?

I have two conditions:

  1. The next line of command has nothing to do with the page being loaded.
  2. The page needed to be continued to load.

Example:

Driver.findeelementby("SignIn").click();
System.out.println("Random Done");

After the click, the page takes 30-40 seconds to load. So, I want the o/p to be displayed as "Random Done" immediately after the click is performed and not to wait for those 30-40 seconds.

After a minute or so, I will perform the actions to the page loaded manually.

*Hope I'm not confusing.

答案1

得分: 0

我们有显式等待条件来等待元素加载完成。
如果您的代码中已经存在,请移除显式、流畅、隐式等待条件。

我认为您不需要实现这个,我认为Selenium已经有了这个功能,这就是为什么我们有这么多用于显式等待的条件,比如:"wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath")));"

英文:

We have explicit wait conditions to wait for the elements to be loaded.
Remove the explicit, fluent, implicit wait conditions if you've in your code.

You don't need to implement this I think it is already there in Selenium that is why we've so many conditions for explicit wait like "wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath")));"

答案2

得分: 0

我发现没有这样的方法,唯一最好的选择是在我们想要对不同的URL执行并行测试的情况下使用多线程的概念。

英文:

I found that there is no such way and the only best possible option is to use the multithreading concept in case if we're looking to perform parallel tests on different URLs.

huangapple
  • 本文由 发表于 2020年8月29日 21:52:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/63647716.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定