다른 미터법 시스템이있는 웹 사이트를 자동화하려고합니다. 응용 프로그램은 미국 메트릭 시스템 & 영국 메트릭 시스템을 모두 지원합니다. 예 : 아메리칸 서버에서 응용 프로그램을 열 경우 센티미터로 텍스트 상자가 나타나는 다른 서버에서 동일한 응용 프로그램을 열면 피트 & 인치의 텍스트 상자가 표시됩니다. &이 표시됩니다. 피트 & 인치를 가진 텍스트 상자 요소가 그 다음 현재의 경우는 &는 피트 & 인치가없는 다른 경우, 그 텍스트 상자에 값을 입력 앞서 간다, 존재 최초로 확인하는 경우 있도록 내 코드를 작성했습니다요소를 찾을 수 없습니다 - 셀렌 웹 드라이버를 사용하여 다른 로케일에서 웹 사이트 자동화하기
, 센티미터 텍스트 상자에 값을 입력하십시오.
/*
*
* 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']"}
누군가가이 문제를 해결하기 위해 나를 인도 할 수
: 요소를 찾을 수 없습니다를 ?감사
귀하의 제안에 따라 코드를 변경했지만 상태 확인에 문제가 있습니다. – AdiBoy
@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
WebElements가 포함 된 목록에서 sendKeys를 호출 할 수 없습니다. 따라서 목록 크기가 0보다 크면 조건이 충족됩니다.찾고있는 요소를 목록에서 추출해야합니다. 목록에서 get (0) 메서드를 사용하여 WebElement를 가져옵니다. 그런 다음 sendKeys 메서드를 사용하십시오. – Grasshopper