Sometimes yous demand to extract specific types of spider web elements from software spider web page similar extract all Links to opened upwardly all of them 1 yesteryear one, extract all text boxes from page to type about text In all of them or In about of them 1 yesteryear one. Previously nosotros bring learnt how to extract all links from software spider web page In THIS POST. Now supposing yous have a scenario where yous needs to extract all text fields from software spider web page to post about text In all of them how to produce It In selenium WebDriver?
You tin privy VIEW MORE TUTORIALS ON SELENIUM WEBDRIVER.
WebDriver's In built findelements method volition deal us to discovery all text boxes from software spider web page. If yous know, Each elementary text box are Input fields too volition bring ever attribute type = text too If It Is password text box too thence It's type volition survive password equally shown In bellow given Image.
In curt nosotros bring to discovery all those Input fields where type = "text" or "password". In bellow given example, I bring used findelements method to discovery too shop all those elements In txtfields array listing too and thence used for loop to type about text In all of them.
package Testng_Pack; import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; populace course of written report Extract_Text { WebDriver driver; @BeforeTest populace void StartBrowser() { driver = novel FirefoxDriver(); } @Test populace void Text() throws InterruptedException{ driver.get(" "); //find all input fields where type = text or password too shop them In array listing txtfields. List<WebElement> txtfields = driver.findElements(By.xpath("//input[@type='text' or @type='password']")); //for loop to post text In all text box 1 yesteryear one. for(int a=0; a<txtfields.size();a++){ txtfields.get(a).sendKeys("Text"+(a+1)); } Thread.sleep(3000); } @AfterTest populace void CloseBrowser() { driver.quit(); } }
This means nosotros tin privy extract all text box from software spider web page If required In whatever scenario.
http://www.software-testing-tutorials-automation.com/