tag:blogger.com,1999:blog-4582236596617205324.post1672455354458659532..comments2014-02-26T23:18:53.804-08:00Comments on Automation Testing with Webdriver: Creating Object Repository in Selenium WebDriver Rajendrahttp://www.blogger.com/profile/01117605235910549617noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-4582236596617205324.post-43950548298245081652014-02-26T23:18:53.804-08:002014-02-26T23:18:53.804-08:00You need to have a "rowcount" keyword in...You need to have a "rowcount" keyword in ur script which will get you the number of rows at runtime. Similarly "columncount". I had done it using Selenium RC. if you want you can make your script "Selenium Backward Compatible" and use these built in functions.Sriharsha Karanhhttps://www.blogger.com/profile/09922956433206467840noreply@blogger.comtag:blogger.com,1999:blog-4582236596617205324.post-31916539741877752662014-02-20T05:56:06.429-08:002014-02-20T05:56:06.429-08:00Kanhaiya, I thought of updating a separate post to...Kanhaiya, I thought of updating a separate post to work with Web Tables,But i am hardly finding time.meanwhile you can refer this example to work with dynamic web tables<br /><br /><br />package testscripts;<br /><br />import java.util.List;<br />import java.util.regex.Pattern;<br />import java.util.concurrent.TimeUnit;<br />import org.junit.*;<br />import static org.junit.Assert.*;<br />import org.openqa.selenium.*;<br />import org.openqa.selenium.firefox.FirefoxDriver;<br /><br />/**<br /> * <br /> * @author Rajendra chary<br /> *<br /> */<br /><br />public class WorkingWithWebTables {<br /> private WebDriver driver;<br /> private String baseUrl;<br /> private StringBuffer verificationErrors = new StringBuffer();<br /> <br /> @Before<br /> public void setUp() throws Exception {<br /> driver = new FirefoxDriver();<br /> baseUrl = "http://dev.mysql.com/";<br /> driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);<br /> }<br /><br /> @Test<br /> public void testWebTable() throws Exception {<br /> <br /> driver.get(baseUrl + "doc/index-enterprise.html");<br /> <br /> //Identifying the webtable <br /> WebElement table=driver.findElement(By.xpath("//table[@class='docs-document-list']"));<br /> // WebElement table =driver.findElement(By.className("docs-document-list"));<br /> <br /> <br /> //Finding out the row collection<br /> List rowCollection=table.findElements(By.xpath("//table[@class='docs-document-list']/tbody/tr"));<br /> //Finding out the row count<br /> int rowcount=rowCollection.size();<br /><br /> System.out.println("Number of rows in this table: "+rowCollection.size());<br /> <br /> int i_RowNum=1;<br /> for(WebElement rowElement:rowCollection)<br /> {<br /> List colCollection=rowElement.findElements(By.xpath("td"));<br /> int i_ColNum=1;<br /> for(WebElement colElement:colCollection)<br /> {<br /> System.out.println("Row "+i_RowNum+" Column "+i_ColNum+" Data ="+colElement.getText());<br /> i_ColNum=i_ColNum+1;<br /> }<br /> i_RowNum=i_RowNum+1;<br /> }<br /> }<br /><br /> @After<br /> public void tearDown() throws Exception {<br /> //driver.quit();<br /> String verificationErrorString = verificationErrors.toString();<br /> if (!"".equals(verificationErrorString)) {<br /> fail(verificationErrorString);<br /> }<br /> }<br /><br /> private boolean isElementPresent(By by) {<br /> try {<br /> driver.findElement(by);<br /> return true;<br /> } catch (NoSuchElementException e) {<br /> return false;<br /> }<br /> }<br />}<br />Rajendrahttps://www.blogger.com/profile/01117605235910549617noreply@blogger.comtag:blogger.com,1999:blog-4582236596617205324.post-8667843677355211112014-02-18T07:04:35.642-08:002014-02-18T07:04:35.642-08:00Very Nice Article. Keep Posting :)Very Nice Article. Keep Posting :)Gaurav Kumar Khannahttps://www.blogger.com/profile/08161310104472224701noreply@blogger.comtag:blogger.com,1999:blog-4582236596617205324.post-75371674491765391882014-02-17T04:06:45.995-08:002014-02-17T04:06:45.995-08:00Hi ,
I have a question , If I have a table which ...Hi ,<br /><br />I have a question , If I have a table which rows & column count is dynamically changing every time then how i can know the count of rows & column.<br /><br />Let me know.Anonymoushttps://www.blogger.com/profile/04654936389836194673noreply@blogger.comtag:blogger.com,1999:blog-4582236596617205324.post-87616932210436731412014-02-07T11:09:55.980-08:002014-02-07T11:09:55.980-08:00Hi Rajendra
Thank you for your reply and suggest...Hi Rajendra<br /><br />Thank you for your reply and suggestion.<br /><br />Can you please share your knowledge on how to prepare a hybrid framework for selenium webdriver.<br /><br />i searched on web regsrding this but didnt got any good article with example. if you share this knowledge like you explained object repository it will be a great help.Anonymoushttps://www.blogger.com/profile/01011565661467041817noreply@blogger.comtag:blogger.com,1999:blog-4582236596617205324.post-34994485434939303702014-02-07T03:30:58.116-08:002014-02-07T03:30:58.116-08:00Hi Swarnendu,Thanks for your comment,Of course,agr...Hi Swarnendu,Thanks for your comment,Of course,agree with you,It is a basic idea to maintain objects information at centralized place,it has certain limitations,<br /><br />my idea behind this is to store the common objects information,for your case it will look like:<br /><br /><br />ex: GooglePage.DropDownAutoComplete.xpath=//*[@id='gsr']<br /><br /><br />java.util.Listlist_suggestion = driver.findElements(By.xpath(GoogleOR.GetProperty("GooglePage.DropDownAutoComplete.xpath"+"/table/tbody/tr/td[2]/table/tbody/tr['x']/td"));<br /><br />int count = list_suggestion.size();<br /><br />System.out.println("count: " + count );<br /><br />for(int k=1;k<=count;k++)<br />{<br /><br />String s = driver.findElement(By.xpath(GoogleOR.GetProperty("GooglePage.DropDownAutoComplete.xpath")+"/table/tbody/tr/td[2]/table/tbody/tr["+k+"]/td")).getText();<br /><br />System.out.println("Suggestion in row: " + k + " is : " + s );<br />}<br /><br /><br /><br />Benefit:if there is a change in table name,you no need to modify all lines of your code,in reality,it might be used in 100 of scripts,so we can save some time,<br /><br />Drawback :Index part we cannot use in object repository files<br /><br />Thanks<br />Rajendra <br />Rajendrahttps://www.blogger.com/profile/01117605235910549617noreply@blogger.comtag:blogger.com,1999:blog-4582236596617205324.post-33377271048531235482014-02-06T06:55:08.743-08:002014-02-06T06:55:08.743-08:00Suppose i want to automate Google auto complete dr... Suppose i want to automate Google auto complete drop down text , which show during search<br />to do this we need to write some code like<br />java.util.Listlist_suggestion = driver.findElements(By.xpath("//*[@id='gsr']/table/tbody/tr/td[2]/table/tbody/tr['x']/td"));<br /><br />if we use object repository how can we adjust our xpath where we need to pass a variable withing loop<br /><br />java.util.Listlist_suggestion = driver.findElements(By.xpath("//*[@id='gsr']/table/tbody/tr/td[2]/table/tbody/tr['x']/td"));<br /><br />int count = list_suggestion.size();<br /><br />System.out.println("count: " + count );<br /><br />for(int k=1;k<=count;k++)<br />{<br /><br />String s = driver.findElement(By.xpath("//*[@id='gsr']/table/tbody/tr/td[2]/table/tbody/tr["+k+"]/td")).getText();<br /><br />System.out.println("Suggestion in row: " + k + " is : " + s );<br />}Anonymoushttps://www.blogger.com/profile/01011565661467041817noreply@blogger.comtag:blogger.com,1999:blog-4582236596617205324.post-64482497150570794272014-02-06T06:50:59.735-08:002014-02-06T06:50:59.735-08:00This comment has been removed by the author.Anonymoushttps://www.blogger.com/profile/01011565661467041817noreply@blogger.com