Using hashtable for include many values in an array – Webdriver (Java)

Hello again,

I had this new thing that I have learned and use almost every days.

You can use this when you need return many values of some table.This code will return a list of things with a column and theirs line. So, here go the code:

Hashtable valores = new Hashtable<String, String>();

int qtdLinesTblSimAcu = 0;

if(tableSimPresent)

{

String[] cTabelSim = new String[10];

cTabelSim[1] = “ID”;

cTabelSim[2] = “Buyer.Firm”;

cTabelSim[3] = “Buyer.Account”;

cTabelSim[4] = “Buyer.Qty”;

cTabelSim[5] = “Seller.Firm”;

cTabelSim[6] = “Seller.Account”;

cTabelSim[7] = “Seller.Qty”;

cTabelSim[8] = “Price”;

cTabelSim[9] = “Traded.Qty”;

//LET CATCH ALL THE LINES AND PUT IN HASHTABLE

int qtdLinhasTblSim = (Integer) selenium.getXpathCount(//html/tbody/table/tr“)); // CHANGE FOR THE CORRECT XPATH ONLY UNTIL THE TR TAG.

qtdLinesTblSimAcu += qtdLinesTblSim;

if(qtdLinesTblSim > 0)

{

//NAVIGATE FOR LINES AND COLUMNS

for(int l = 2; l <= qtdLinhasTblSim; l++)

{

//NAVIGATE FOR COLUMNS

for(int c = 1 ;c < 10;c++) //CHANGE FOR THE NUMBER OF COLUMNS

{

String val  = selenium.getText(String.format(“xpath=//html/tbody/tr[%s]/td[%s]“),l,c)); /*CHANGE FOR THE XPATH CORRECT, IN THE %s YOU WILL SUBSTITUTE RESPECTIVELY FOR VALUE OF L AND C, LIKE LINE AND COLUMN. */

values.put(cTabelSim[c] + “:” + ((l + qtdLinesTblSimAcu) -1),val);

}

}

}

/* THIS IS THE END OF THE RETURN, IF YOU HAVE CATCH VALUES OF ANOTHER TABLE, PUT THE FOR FOR CATCH THE VALUES OF THIS TABLE, AND THE CODE BELOW IN THE END OF THIS LAST FOR   */

String[][] returnE = new String[values.size()][2];

Enumeration e = values.keys();

int index = -1;

while(e.hasMoreElements())

{

index++;

String k = (String) e.nextElement();

returnE[index][0] = k;

returnE[index][1] = values.get(k).toString();

}

return returnE ;

}

The return will be something like this:

columnA:1 valueA1

columnA:2 valueA2

columnB:1 valueB1

columnC:1 valueC1

columnC:2 valueC2

columnC:3 valueC3

Bye bye, guys !!

Desired capabilities Webdriver – Ignore security in browser

Hello again, I had some codes to show you !

Like this one, when you have some problem with the certificate page, or proxy, or another security problem, you can put this code for initialise the webdriver. Before you code anything, you have to start the webdriver and config this one, you can use this config for start the webdriver with the config of all security is off.

In this example I use the IE 9 and platform windows like the default browser:

DesiredCapabilities capabilities = new DesiredCapabilities(“Internet Explorer”, “9”, Platform.WINDOWS);
capabilities.setJavascriptEnabled(true);
capabilities.setCapability(“ignoreProtectedModeSettings”, true);
capabilities.setCapability(“ensureCleanSession”, true);
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver = new InternetExplorerDriver(capabilities);

 

Bye bye !!

List of how mount expressions of xpath

Hey guys !!

I’m found a interest and very usefull thing for us mount expressions of xpath.

 

Look this site, they have all single expressions and a short explanation for each one.

https://opencast.jira.com/svn/MH/trunk/modules/matterhorn-runtime-info-ui/src/main/resources/uitests/tests/TestXPathLocators.html

I hope this helps you, the same way helps me !

Good bye 🙂

One solution for: Error in execution of Webdriver

Good night,

When you have errors in a execution of webdriver, and for some reason appears a message told that selenium is closed and your selenium doesn’t really closed.

Put this code for initialize the execution:

String Servidor = “http://127.0.0.1:4444/wd/hub“;
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
WebDriver driver = new RemoteWebDriver(new URL(Servidor),capabilities);

This way you will execute the test in your local machine and force this.