image source: pixabay
오늘은 Selenium이 제공하는 Timeouts을 배워 본다. timeouts() 메서드는 manage() 내에 존재하고 아래의 세개 메서드를 제공한다.
1. implicitlyWait
이 아이는 Webdriver편에서 배웠으니 패스.
[JAVA 6#] [Web Automation 6#] Controlling STEEMIT web pages with Selenium #4 WebDriverWait [KR]
2. pageLoadTimeouts
말 그대로 페이지가 모두 로딩되기까지의 타임아웃 시간을 설정한다. 시간을 초과하면 TimeOutException을 던진다.
인자는 time과 시간단위이고, time을 부수로 설정할 경우 무한대로 기다린다. 👇
driver.manage().timeouts().pageLoadTimeout(-1, TimeUnit.SECONDS);
Selenium의 driver.get()
와 driver.navigate().to()
에만 적용된다. 즉 클릭으로 페이지 이동할 때에는 적용되지 않는다.
성능 테스트 혹은 IE 브라우저로 사용할 경우 효과가 있다.
3. setScriptTimeout
비동기시 스크립트 실행 완료 타임아웃을 설정하고 초과하면 TimeOutException을 던진다.
이 메서드는 executeAsyncScript로 작성된 javascipt코드에만 영향을 미치고 다른 코드에는 영향이 없다. executeScript로 작성된 코드도 해당하지 않는다.
또한 executeAsyncScript를 사용할 때 필수로 setScriptTimeout을 설정해야 한다. 이유는 setScriptTimeout의 디폴트 값이 0인데 보통 javascript 코드는 실행시간이 0초가 넘으므로 타임아웃을 설정해 주어야 한다.
package com.steem.webatuo;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
import io.github.bonigarcia.wdm.WebDriverManager;
public class Steemit {
public static void main(String[] args) throws InterruptedException {
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.get("https://steemit.com");
driver.manage().timeouts().setScriptTimeout(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(4, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
Wait<WebDriver> wait = new WebDriverWait(driver, 10);
/**
* Some actions
*/
Thread.sleep(5000);
driver.quit();
}
}
.
.
.
.
[Cookie 😅]
Seleniun java lib version: 3.141.59
- Your funds have been moved into your savings account.
- For more info about my keys protection activity see https://steemit.com/steem/@gaottantacinque/the-keys-defender-bot-is-live-in-beta-mode
Detected after 2477 ms that the block was published (including time for pwd change or deposit to savings when applicable)❗❗❗ 💀💀 ⚠️⚠️ @june0620 You just COMPROMISED your own account leaking a private key!
Thanks!
You’re welcome.
Glad you were able to recover your account!
Please consider delegating to @keys-defender to keep it active as it’s still quite low on RC. Thx! =]
good job on creating a nice bot. I just made some delegation to sustain RC runout.
Wow, thanks man!! 😊 🙏
Hi ~
Thank you. I have delegated @keys-defender some sp.
Thanks guys, much appreciated!!
Thanks for delegating, now I can leave more comments around without worrying about keeping the operations running! =]
@keys-defender