I have a scenario in which one of the parameter value is changing as per the requirement.how to handle this case for andriod,iOS and selendriod.
Eg : public commonPage clickPinId(String pinNumber, int pinSize) {
The above example is for andriod.
In this the “pinNumber” variable in locator is changing,it can be 1,2,3,4…etc.
The above method works fine for Andriod but i want to have a common method for andriod,iOS and selendriod.i am not able to write such locators in @AndriodFindBy or @iOSFindBy
for iOS the locator is driver.findElement(By.xpath("//UIAButton[@label=‘0’]")).click();
please help me with this Case,bit urgent.Thanks in advance.
Hi Degard,
Thanks for the reply.
i am not able to find name or linktext for the element and the value is changing dynamically as per the requirement, as it cane be 123 or 344 …etc
regarding the if condition should i check which driver is instantiated,as i have lot of such changing locators,should i check the driver everytime while calling the method.
You mean you have pinNumber element in iOS ,Android, Android(API <17 … selendroid)
for android app its id is “ban.card.payanywhere:id/pin_”+“dynamicpinNumber”
for iOS app its xpath is //UIAButton[@label=‘0’]
In case u r only problem is dynamic id then u can use below xpath
driver.findElement(By.xpath("//*[starts-with(@id, ‘ban.card.payanywhere:id/pin_’)]")).click();
other wise u need to check driver.instanceOf since u r locators are different or one more method is
// Write this method in BasePage Class
import org.openqa.selenium.Platform;
public int platformCheck(){
Platform current = Platform.getCurrent();
if (current.is(Platform.WINDOWS)){ return 1;}
else if (current.is(Platform.MAC)){ return -1;}
}
public commonPage clickPinId(String pinNumber, int pinSize, int platform) {
if(platform > 0) { // iOS code goes here}
else {driver.findElement(By.id(“ban.card.payanywhere:id/pin_”+pinNumber)).click();}
return this;
}
In your method calling class where u call ‘clickPinId’ call it like this
CommonPageClassObj.clickPinId(“5757”, 4, int platform,platformCheck());