Scenario2:Query on table content & leastperformance scenario | Selenium Forum
M
Posted on 01/05/2016
Sir , in video 11 you use "//a[@text()='Tata Motors Ltd.']"

& say can't store this in properties file as this keeps changing.
[b:2skdd90s]

My Query is :Why not use :List<WebElement>L=new ArrayList<WebElement>();
L=w.findElements(By.className("leastPerf"));[/b:2skdd90s]

[b:2skdd90s]Even if 'Tata Motors Ltd.' updated to something else it would still be under class=leastPerf right....[/b:2skdd90s]

M
Replied on 02/05/2016

check if the name of the class changes. if it doesn't then you can use it.


M
Replied on 02/05/2016

Sir, here is a generic method:

public static Boolean isElementPresent_specific(String Identifier1,int Identifier2,String Identifier3)
{String Locator=CONFIG.getProperty(Identifier1)+Identifier2+CONFIG.getProperty(Identifier3);
APP_LOGS.warn("--------"+CONFIG.getProperty(Identifier1)+Identifier2+CONFIG.getProperty(Identifier3));
APP_LOGS.warn("--------"+Locator.trim());

int size=0;
if((Identifier1.endsWith("_xpath")) & (Identifier3.endsWith("_xpath")))
{
//String Locator=CONFIG.getProperty(Identifier1)+Identifier2+CONFIG.getProperty(Identifier3);
APP_LOGS.warn("--------"+CONFIG.getProperty(Identifier1)+Identifier2+CONFIG.getProperty(Identifier3));
size=w.findElements(By.xpath(Locator.trim())).size();
}
/*else
if(Identifier.endsWith("class"))
size=w.findElements(By.className(CONFIG.getProperty(Identifier))).size();
if(Identifier.endsWith("_Id"))
size=w.findElements(By.id(CONFIG.getProperty(Identifier))).size();
*/
if(size>0)
return true;
else return false;//EmailField_Id
}


[b:2r5k45kg]I passed following parameters:
APP_LOGS.warn("Matching % stock element is present?:"+isElementPresent_specific("Percentage_Table_xpath1",(index+1),"Percentage_Table_xpath2"));

with @ CONFIG.properrties file

Percentage_Table_xpath1=//table[@id='stock']/tbody/tr[
Percentage_Table_xpath2=]/td[10]

Issues is : This call to function always returns a false.[/b:2r5k45kg]
[b:2r5k45kg]Please find my project as attachment ,SuiteB>Leastperformance[/b:2r5k45kg]


M
Replied on 04/05/2016

i couldn't understand you code. can you be little clearer.


M
Replied on 04/05/2016

Sir,

[b:j692y62m]properties file :[/b:j692y62m]
Percentage_Table_xpath1=//table[@id='stock']/tbody/tr[
Percentage_Table_xpath2=]/td[10]

Pls refer , snapshot....

i need to get text of object with tr[3] i.e. //table[@id='stock']/tbody/tr["+(3)+"]/td[10]
Am trying to evaluate if the above element isElementPresent...

Function always returns me false if i pass respective values from
:
========================================================================================
public static Boolean[b:j692y62m] isElementPresent_specific[/b:j692y62m](String Identifier1,int Identifier2,String Identifier3)
{String Locator=CONFIG.getProperty(Identifier1)+Identifier2+CONFIG.getProperty(Identifier3);
APP_LOGS.warn("--------"+CONFIG.getProperty(Identifier1)+Identifier2+CONFIG.getProperty(Identifier3));
APP_LOGS.warn("--------"+Locator.trim());

int size=0;
if((Identifier1.endsWith("_xpath")) & (Identifier3.endsWith("_xpath")))
{
//String Locator=CONFIG.getProperty(Identifier1)+Identifier2+CONFIG.getProperty(Identifier3);
APP_LOGS.warn("--------"+CONFIG.getProperty(Identifier1)+Identifier2+CONFIG.getProperty(Identifier3));
size=w.findElements(By.xpath(Locator.trim())).size();
}

if(size>0)
return true;
else return false;//EmailField_Id
}

[b:j692y62m]
Call is :[/b:j692y62m]
String MatchingStockPercentage="Percentage_Table_xpath1"+(index+1)+"Percentage_Table_xpath2";// index is 2
isElementPresent_specific("MatchingStockPercentage");
[b:j692y62m]
Issue is :Above call returns false all the time....[/b:j692y62m]
But if i directly give [b:j692y62m]APP_LOGS.warn("*******"+w.findElement(By.xpath("//table[@id='stock']/tbody/tr["+(3)+"]/td[10]")).getText());[/b:j692y62m] & respective isElementPresent rretuens true...

Responsive image