2016-08-29 2 views
0

가져가 요소에 드롭 다운을 찾을 수 없습니다 I 요소를 안정적으로 선택할 수 없습니다. 이것은 내가 디버깅있어 시간의 100 % 작동하지만이 부착 된 디버거없이 실행할 때 시간의 약 2/2/3 실패합니다. 여기에 코드입니다 :셀레늄 드라이버 (크롬), I는하지만, 여러 사이트 환경에 대한 몇 가지 테스트를 실행하는 셀레늄 크롬 드라이버를 사용하고

private void prepWindow(WebDriver driver, boolean isNightly, String toClick) { 
    WebDriverWait wait = new WebDriverWait(driver, 300); 

    try { 
     if (isNightly) { 
      WebElement nightlyPopup = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(BOWebElements.nightlyPopup))); 
      nightlyPopup.click(); 
     } 
    } catch (Exception e) { 
     JOptionPane.showMessageDialog(null, "Nightly popup has changed names again.", "Error", JOptionPane.ERROR_MESSAGE); 
    } 

    WebElement user = wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Users"))); 
    Actions action = new Actions(driver); 

    action.moveToElement(user).build().perform(); //Makes hover drop down appear 
    driver.findElement(By.id(toClick)).click(); //Should click element that is only visible when hover drop down is open 
} 

나는 또한 같은 위의 코드는 동료의 컴퓨터에서 디버거를 사용하지 않고 완벽하게 작동하지만 내 자신하지 않도록주의해야한다.

나는 아래로 실제로 내가 드롭 다운을 열 위로 마우스를 이동해야하는 링크의 자녀하지 XPath는하지만 드롭의 불행하게도 요소를 사용하고 싶습니다. 나는 XPath를 사용하여 요소로 직접 이동하려고하면, 그것은 나에게는 XPath가 유효하지 않다는 오류를 제공합니다. 다음은 잠재적 인 XPath 중 하나입니다.

//html/body/#outTemplateId/#preambleFormId/#globalNavigation/#navBGC/#navBGCmainMM/ul/li/ul/table/tbody/tr/td/ul.ui-menu-list.ui-helper-reset/li.ui-menuitem.ui-widget.ui-corner-all/a#fleetUsersId2.ui-menuitem-link.ui-corner-all.submenu 

어떻게 동작을 일관되게 만들 수 있습니까?

+0

을 당신이 마지막 줄을 변경해야'드라이버 .findElement (By.id (toClick)) (클릭).'wait.until'에 (ExpectedConditions.elementToBeClickable (By.id (toClick))) (클릭).'..이 일 때마다 –

+0

일 것입니다 @ SaurabhGaur 동일한 오류/결과. –

답변

1

체인 더 나은 행동을 모방하기 위해 함께 당신의 행동은 사용자가 수행하게 :

action.moveToElement(user).moveToElement(driver.findElement(By.id(toClick))).click().build().perform();

체크 아웃 자세한 내용은이 질문 : https://stackoverflow.com/a/17294390/3537915

관련 문제