Reputation: 155
I'm trying to automate a website which has different metric systems. The application supports both the American metric system & British metric system. For Ex : In case I open the application from an american server I see the textboxes for Feet & inches, & if I open the same application from a different server I see the textboxes in Centimeters.
I've written my code so that it first checks if an textbox element with Feet & Inches is present, if it's present then it goes ahead & enters values in those text boxes, else if Feet & Inches ain't present, then enter the values in Centimeters textbox.
/*
*
* 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;
And my code to check if it's in either version is as below.
public void userFitnessDetails() {
CurrentWeight.sendKeys("70");
if (CurrentHeightinFeet.isDisplayed()) {
CurrentHeightinFeet.clear();
CurrentHeightinFeet.sendKeys("5");
CurrentHeightinInches.clear();
CurrentHeightinInches.sendKeys("10");
}
CurrentHeightinCM.clear();
CurrentHeightinCM.sendKeys("170");
}
If I execute the above code I get an error - FAILED: signUp org.openqa.selenium.NoSuchElementException: Unable to locate element:
{"method":"xpath","selector":".//*[@id='profile_height_large_value']"}
Could someone guide me to correct this?
Thanks
Upvotes: 0
Views: 65
Reputation: 9058
Assumptions - You are working on a british server and running into issues with the american feet-length inputs. Page is completely loaded and elements fully available, so wait issues are not present.
You will run into problems with the isDisplayed()
method. It is used to figure out if an element that is present in the page is not visible or vice versa due to the style attribute display setting. Here you have mentioned depending on server location the relevant html elements are present or not. If the element is not available then you will see the exception.
You can use the safer driver.findElements()
, in place of isDiplayed()
condition check, which returns a list and you can check the size to determine availability.
Upvotes: 1