目前,我正在利用一种工作方法在指定的超时后终止 Selenium get
线程,这是我在 Stack Overflow 上找到的...
String url = "https://www.myurl.me";
Integer timeout = 3000;
Thread t = new Thread(new Runnable() {
public void run() {
driver.get(Thread.currentThread().getName());
}
}, url);
t.start();
try {
t.join(timeout); // <--- Timeout specified in milliseconds
}
catch (InterruptedException e) { // ignore
}
if (t.isAlive()) { // Thread still alive, we need to abort
System.out.println("Timeout on loading page " + url);
t.interrupt();
}
但是,我需要另一种方法来在指定的时间长度后终止 Selenium click
线程,因此如果链接上的点击挂起,则该线程将被终止。基本上我想杀死这样的东西......
driver.findElement(By.xpath(relXpath)).click();
关于如何修改我的上述代码以终止 click
而不是 get
有什么建议吗?
最佳答案
Thread t = new Thread() {
public void run() {
driver.findElement(By.xpath(elementXpath)).click();
}
};
t.setName("runThread");
t.start();
try {
t.join(3000); // <--- Timeout specified in milliseconds
}
catch (InterruptedException e) { // ignore
}
if (t.isAlive()) { // Thread still alive, we need to abort
System.out.println("Timeout on loading on xpage "+ monkeyPath);
t.interrupt();
}
关于java - 如何在超时后杀死 Selenium "Click"线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27707401/