目前,我正在使用一种工作方法在我在Stack Overflow上找到的指定超时后杀死Selenium get
线程...
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
的任何建议?
答案 0 :(得分:1)
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();
}