2017-04-04 2 views
0

TestNG 프레임 워크를 사용하여 셀렌 스크립트를 작성하고 있습니다. 셀레늄이 NoSuchElement 예외를 throw하기 전에 명시 적 대기 시간을 20 초로 정의했습니다. 하지만 스크립트는 실행 중에 20 초를 기다리지 않고 41 밀리 초 안에 예외를 throw합니다. 나는 예외를 던지기 전에이 스크립트가 (명시 적 대기만을 사용하여) 대기하거나 20 초 동안 웹 요소를 검색하길 원합니다.셀레늄 스크립트가 명시 적 대기 시간에 정의 된 시간만큼 길지 않습니다.

다음은 실행 결과가 표시된 스크립트입니다.


public class para { 
WebDriver driver; 

@BeforeClass 
void InvokeFF() { 
    System.setProperty("webdriver.gecko.driver", 
      "C:/Users/Vinay/workspace_n/EGuru/drivers/geckodriver.exe"); 
    driver = new FirefoxDriver(); 
    // driver.get("http://seleniumpractise.blogspot.in/2016/08/bootstrap-dropdown-example-for-selenium.html"); 
    System.out.println("Firefox invoked"); 
    System.out.println("Firefox thread:" + Thread.currentThread().getId()); 

} 

@Test 
void Auto() throws Exception { 
    WebDriverWait wait = new WebDriverWait(driver, 20); 
    driver.get("file:///C:/Users/Vinay/Desktop/Upload1.html"); 
    WebElement elem = driver.findElement(By.xpath(".//*[@id='1']")); 
    wait.until(ExpectedConditions.visibilityOfElementLocated(By 
      .xpath(".//*[@id='1']"))); 
    elem.click(); 
    Runtime.getRuntime().exec("C:\\Users\\Vinay\\Desktop\\AutoUpload.exe"); 
} 
파이어 폭스 파이어 폭스 스레드를 호출 : 1 개 실행은 [의 Utils] C를 만들 을 시도 시작일 : \ 사용자 인 Vinay을 \ \ workspace_n \ EGuru \ 테스트 출력 \ 기본 스위트 \ 기본 test.xml의 [Utils] 디렉토리 C : \ Users \ Vinay \ workspace_n \ EGuru \ test-output \ 기본 패키지가 존재 함 : 참 : 자동 org.openqa.selenium.NoSuchElementException : Unable 요소를 찾으려면 을 찾을 수 없습니다. { "method": "xpath ","selector ":".//*[@id = '1'] "} 명령 지속 시간 또는 시간 초과 : 41 밀리 초 th오류 : http://seleniumhq.org/exceptions/no_such_element.html 빌드 정보 : 버전 : '2.53.0', 개정 : '35ae25b', 시간 : '2016-03-15 16:57:40 ' 시스템 정보 : 호스트 :'Vinay- PC : 'ip :'192.168.1.2 ', os.name :'Windows 7 ', os.arch :'amd64 ', os.version :'6.1 ', java.version :'1.8.0_101 ' 드라이버 정보 : org.openqa.selenium.firefox.FirefoxDriver 기능 [{applicationCacheEnabled = true, 회전 가능 = false, handlesAlerts = true, databaseEnabled = true, 버전 = 45.0.2, 플랫폼 = WINDOWS, nativeEvents = false, acceptSslCerts = true, webStorageEnabled = true, locationContextEnabled = true, browserName = firefox, takesScreenshot = true, javascriptEnabled = true, cssSelectorsEnabled = true}] 세션 ID : d40fc001-400c-473b-8213-078e641b3c7f *** 요소 정보 : {using = xpath, value =. // * [@ id = '1']} at sun.reflect .NativeConstructorAccessorImpl.newInstance0 (자국어 법)

답변

0
WebElement elem = driver.findElement(By.xpath(".//*[@id='1']")); 
wait.until(ExpectedConditions.visibilityOfElementLocated(By 
     .xpath(".//*[@id='1']"))); 

위의 두 줄은 역순으로 될 필요가있다. 기다리지 않고 요소를 얻으려고 시도하는 중입니다. 그런 다음 웹 드라이브가 기다릴 때까지 기다리라고 말합니다.

+0

효과가있었습니다. 감사합니다. – iAutomate

관련 문제