Selecting checkbox Is non big draw of piece of job In selenium webdriver If banking corporation tally box has ID, Name or whatever other proper locator. You tin banking corporation tally It real easily using .Click() method. .Click() Is generic method in addition to yous can use It to click on whatever chemical factor similar select radio button, check the banking corporation tally box or clicking on
any other element. But supposing yous convey a listing of Items alongside checkbox in addition to whatever checkbox create non convey whatever Identifier thence how volition yous choose specific checkbox? NEXT POST volition depict how to choose checkbox from tabular array using following-sibling and following-sibling
Solution ane : Using Absolute XPath
Consider checkbox listing given on THIS PAGE. All the checkbox convey type attribute alongside same value checkbox. Any of them create non convey whatever proper locator using which I tin locate specific checkbox. I wants to choose banking corporation tally box which Is located In "Cow" row. One means Is using absolute XPath every bit bellow.
//div[@id='post-body-536524247070242612']/div[1]/table/tbody/tr[3]/td[1]/input
At house of using absolute XPath, We tin usage functions similar last() in addition to position() In XPath to locate specific checkbox.
Read to a greater extent than webdriver tips in addition to tricks on THIS PAGE.
Read to a greater extent than webdriver tips in addition to tricks on THIS PAGE.
Solution ii : Using position() Function In XPath
In bellow given xpath, [@type='checkbox'] volition locate checkbox in addition to function [position()=3] volition locate checkbox which Is located on third seat from top. You tin modify your seat publish every bit per requirement.
xpath=(//input[@type='checkbox'])[position()=3]
Solution iii : Using last() Function In XPath
In bellow given xpath, [last()-1] business office volition locate 2d end checkbox which Is for Lion.
xpath=(//input[@type='checkbox'])[last()-1]
To locate end checkbox, You tin usage It every bit bellow.
xpath=(//input[@type='checkbox'])[last()]
Here Is the practical webdriver example to choose checkbox using position() in addition to last() functions.
package Testing_Pack; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; populace degree Checkboxpos { WebDriver driver; @BeforeTest populace void setup() throws Exception { driver =new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get(" "); } @Test populace void selectCheck(){ //To choose Cow checkbox using position() function. driver.findElement(By.xpath("(//input[@type='checkbox'])[position()=3]")).click(); //To choose Lion checkbox using last() function. driver.findElement(By.xpath("(//input[@type='checkbox'])[last()-1]")).click(); //To choose Tiger checkbox using last() function. driver.findElement(By.xpath("(//input[@type='checkbox'])[last()]")).click(); } }
You tin usage same affair for whatever chemical factor to locate It from listing of same Items. You tin acquire how to acquire XPath or CSS path of whatever chemical factor using firebug in addition to firepath every bit described inward THIS POST.
More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM
http://www.software-testing-tutorials-automation.com/