2016-10-22 2 views
0

다른 미터법 시스템이있는 웹 사이트를 자동화하려고합니다. 응용 프로그램은 미국 메트릭 시스템 & 영국 메트릭 시스템을 모두 지원합니다. 예 : 아메리칸 서버에서 응용 프로그램을 열 경우 센티미터로 텍스트 상자가 나타나는 다른 서버에서 동일한 응용 프로그램을 열면 피트 & 인치의 텍스트 상자가 표시됩니다. &이 표시됩니다. 피트 & 인치를 가진 텍스트 상자 요소가 그 다음 현재의 경우는 &는 피트 & 인치가없는 다른 경우, 그 텍스트 상자에 값을 입력 앞서 간다, 존재 최초로 확인하는 경우 있도록 내 코드를 작성했습니다요소를 찾을 수 없습니다 - 셀렌 웹 드라이버를 사용하여 다른 로케일에서 웹 사이트 자동화하기

, 센티미터 텍스트 상자에 값을 입력하십시오.

/* 
* 
* This block is for the values in US version 
* 
*/ 
@FindBy(xpath = ".//*[@id='profile_height_large_value']") 
WebElement CurrentHeightinFeet; 

@FindBy(xpath = ".//*[@id='profile_height_small_value']") 
WebElement CurrentHeightinInches; 

/* 
* This block is for the values in British version 
* 
*/ 

@FindBy(xpath = ".//*[@id='profile_height_display_value']") 
WebElement CurrentHeightinCM; 

그리고 내 코드는 두 버전의 경우 다음과 같습니다 확인합니다. 나는 위의 코드를 실행하면

public void userFitnessDetails() { 
    CurrentWeight.sendKeys("70"); 

    if (CurrentHeightinFeet.isDisplayed()) { 
     CurrentHeightinFeet.clear(); 
     CurrentHeightinFeet.sendKeys("5"); 
     CurrentHeightinInches.clear(); 
     CurrentHeightinInches.sendKeys("10"); 
    } 

    CurrentHeightinCM.clear(); 
    CurrentHeightinCM.sendKeys("170"); 
} 

오류가 발생합니다 - 실패 : 가입 org.openqa.selenium.NoSuchElementException :

{"method":"xpath","selector":".//*[@id='profile_height_large_value']"} 

누군가가이 문제를 해결하기 위해 나를 인도 할 수

: 요소를 찾을 수 없습니다를 ?

감사

답변

1

가정 - 당신은 영국 서버에서 작업하고, 미국 피트 길이의 입력에 문제로 실행하고 있습니다. 페이지가 완전히로드되고 요소가 모두 사용 가능하므로 대기 문제가 없습니다.

isDisplayed() 메서드로 문제가 발생합니다. 스타일 속성 표시 설정으로 인해 페이지에있는 요소가 보이지 않거나 그 반대 인 경우를 찾습니다. 여기서는 관련 html 요소가 존재하는지 여부에 따라 서버 위치에 따라 언급했습니다. 요소가 사용 가능하지 않으면 예외가 표시됩니다.

isDiplayed() 상태 확인 대신 안전한 driver.findElements()을 사용할 수 있습니다. 그러면 목록이 반환되고 크기를 확인하여 사용 가능 여부를 확인할 수 있습니다.

+0

귀하의 제안에 따라 코드를 변경했지만 상태 확인에 문제가 있습니다. – AdiBoy

+0

@FindBy (xpath = ".//*[id='profile_height_display_value ']")) \t WebElement CurrentHeightinCM; \t @FindAll (@FindBy (id = "profile_goal_weight_display_value")) \t WebElement GoalWeight; 또한 내 상태 검사에서 사용하는 경우 (CurrentHeightinFeet.size()> 0 && CurrentHeightinInches.size()> 0) { \t \t \t CurrentHeightinFeet.clear(); \t \t \t CurrentHeightinFeet.sendKeys ("5"); \t \t \t CurrentHeightinInches.clear(); \t \t \t CurrentHeightinInches.sendKeys ("10"); \t \t} "List 유형에 대해 sendKeys (String) 메서드가 정의되지 않았습니다. " – AdiBoy

+1

WebElements가 포함 된 목록에서 sendKeys를 호출 할 수 없습니다. 따라서 목록 크기가 0보다 크면 조건이 충족됩니다.찾고있는 요소를 목록에서 추출해야합니다. 목록에서 get (0) 메서드를 사용하여 WebElement를 가져옵니다. 그런 다음 sendKeys 메서드를 사용하십시오. – Grasshopper

관련 문제