본문 바로가기
소프트웨어 개발/비주얼스튜디오(Visual Studio)

[C#/Selenium WebDriver] 특정 요소가 화면에 보일 때 까지 기다리는 방법

by Sakriun_to 2022. 6. 21.
728x90

1. [NuGet 패키지 관리]에서 [DotNetSeleniumExtras.WaitHelpers] 설치

 

2. 아래 소스 추가!

- css 요소가 화면에 보일때까지 대기.

// 화면에 요소가 보일 때까지 대기
private static bool ElementWait(IWebDriver driver, By by)
{
    WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));

    try
    {
    	IWebElement element = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(by));
    }
    catch (Exception e)
    {
    	return false;
    }
    return true;
}


public void WaitData()
{
	// [ElementWait] 사용하기
	ElementWait(driver, By.CssSelector(".se-image-resource"));
}
728x90
반응형

댓글