Wednesday, October 7, 2015

How to verify the text into the Whole WebPage

set objpage = Browser("Google").Page("Google")

set objpage = Browser("Google").Page("Google")


msgbox   VerifyTextPresentOnPage(objpage ,"zeeshan" )

'-----------------------------------------------------------------------------------------------------------------------------
'Functioen name : VerifyTextPresentOnPage

'Created by  : Zeeshan Khan

'--------------------------------------------------------------------------------------------------------------------------------
Function VerifyTextPresentOnPage(objpage ,Textvalue )


'Child object description
Set childobjdes = Description.Create()
childobjdes("micclass").value="WebElement"
childobjdes("html tag").value=".*[A-Za-z0-9].*"
childobjdes("outertext").value =".*[A-Za-z0-9].*"

'Get ALL child object
set allobj = objpage.ChildObjects(childobjdes)
'get all  web element  outer text from web page and store in output variable
For i=1 to allobj.count-1
output=  output   & allobj.Item(i).GetROProperty("outertext")
Next
'now compare the value if the given value find or not
print output
If instr(1,lcase(output),lcase(Textvalue)) > 0  Then
'return true if found
VerifyTextPresentOnPage= True
Print VerifyTextPresentOnPage
Else
'return true if  not found
VerifyTextPresentOnPage= False
Print VerifyTextPresentOnPage
End If
End Function

Sunday, September 27, 2015

Working on Webtables in Selenium with the use of Java

What is Webtable?
Web tables are basically group of elements that are logically stored in a row and column format. 
  1.  If we know that number or rows and Columns are fixed than we will use the below approach
1for(int numberOfRows=1; numberOfRows<=5; numberOfRows++)
2{
3for(int numberOfCol=1; numberOfCol <=3; numberOfCol++)
4{
5System.out.println(driver.findElement(By.xpath(“//div[@id='main']/table[1]/tbody/tr[“+numberOfRows+”]/th[“+numberOfCol+”]”)));
6}
7}

  1.      How to work with the dynamically changed webtables?
1WebElement htmltable=driver.findElement(By.xpath("//*[@id='main']/table[1]/tbody"));
2List<WebElement> rows=htmltable.findElements(By.tagName("tr"));
3 
4for(int rnum=0;rnum<rows.size();rnum++)
5{
6List<WebElement> columns=rows.get(rnum).findElements(By.tagName("th"));
7System.out.println("Number of columns:"+columns.size());
8 
9for(int cnum=0;cnum<columns.size();cnum++)
10{
11System.out.println(columns.get(cnum).getText());
12}
13}