Step by step selenium – step 3, what is findelement method

Selenium Basic
1

Abstract-

So far, we have learned how to launch a web browser, entering values in a text box and clicking button.
In this post, we will learn about findelement method.

Test automation is all about get and set, which means get from web and set into web.

Talking more specifically-

What I meant from get is, reading a webobject property e.g. Reading a label value of web, which is using findelement.

What I meant by set is, setting values in web for e.g. Inserting values in a text box, clicking a button, selecting a radio button, again using findelement method.

So findelement is a method which helps in interaction with a web page.

How it’s represented and does it work-

It’s written as –

Driver. Findelement(By. Id("")). Click().

WebDriver object allows access to findelement and with help of web object property is finds the designated object and perform operation.

There is another method which is known as findelements.

What is findelements()?

If a web object returns multiple values then findelements are used.

There should be some list, set or array variable be mentioned on the left side which can contain/store returned values-

It’s represented as-

List <WebElement> list= driver. Findelements(By. Id() ) ;

If you can compare with findelement method there is no click or get text method called. Same is done while in list object by iterating it Inside a loop.

For(el:list)

{

el. Gettext() ;
or
el.click();

}

Common Questions-

1- What is the difference bewteen findelement and findelements

Answer- Findelement return single element where as findelements return multiple elements

2- What is the data type which find element or findelements return.

Answer- String

3- What are possible cases when findelement return nothing or null or exception

Answer- Case 1- When page is not loaded when findelement is being called
Case 2- When element property is changed
Case 3- When there is a frame is introduced

Summary-

Findelement, findelements method is accessed uding webdriver object whic is an interface. They helps in locating a web element or group of elements which have same properties.

It also helps in interaction which ultimately create a bridge between web page and you test/test data and execute test automation script.

Stay connected, In our next post we will learn how to find Xpath and CssSelector

Its Prashant Chaudhary, I have 10+ years of experience in software test automation, performance & process automation with various commercial and open source tools. This blog shares my experience on the topic of Automation. The content published on my blog is solely mine, it does not express the views of any of my employers (current or previous).

String chromepath;
WebDriver driver;
chromepath = “./Resources/chromedriver”;
System.setProperty(“webdriver.chrome.driver”, chromepath+”.exe” );
driver = new ChromeDriver();

driver.get(“www.google.com”);

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

driver.findElement(By.name(“q”)).sendKeys(“Automatorsworld”);

driver.findElement(By.cssSelector(“[name=’btnK’]”)).click();

WebDriverWait wait new WebDriverWait(driver, 45);
wait.until(ExpectedConditions.visibilityOfElementLocated(locator))

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Selenium Basic
2
Step by step selenium – step 4, Finding X-path…1/2

In Selenium test automation, if webobject properties does not have id, name, class then we left with 2 options- Option 1 calculate xpath Option 2 Calculate XssSelector In this post, we will calculate about the xpath and various XPath expression for webobjects whose attributed are changing dynamically. There are 2 …

Selenium Basic
Step by step selenium – step 2 -How to enter value in text box and how to click a button.

Abstract- In Previous post, we have learnt how to launch a web-browser in selenium. In this post we will learn how to enter values in a text box and how to click a button. We will be using chrome browser for this posts well. package TestNG_Classes; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; …

Selenium Basic
Step by step selenium – step 1, How to launch a web browser

Introduction – In this blog post, we will see how to run first test in selenium and what are necessary configuration required for invoking browser. There are 2 basic configuration to invoke a browser. First step, download and configure selenium standalone jar. Visit -https://www.seleniumhq.org/download/ , Refer below screenshot. Config the …

Shares