1.How to verify tooltip text using Selenium WebDriver
A tooltip is what is entered in the title attribute of an
element. The Browsers will pop up a little box showing the content of the title element when you
mouse over an element. IE makes things a bit blurry because they will show
the alt attribute of an element if the title element is not populated
public class Tooltips
{
public static
void main(String args[])
{
WebDriver
driver = new WebDriver();
driver=new FireFoxDriver();
driver.get("http://www.menucool.com/tooltip/css-tooltip");
WebElement
element=driver.findElement(By.linkText("Tooltip"));
Actions
builder = new Actions(driver); // Here we use Action for interaction
Action
mouseOver =builder.moveToElement(element).build();
mouseOver.perform();
// perform action on element
if(driver.findElement(By.className("code")).isDisplayed())
{
String Tooltip=driver.findElement(By.className("code")).getText());
System.out.println("Tooltip is coming");
System.out.println("Tool tip text is:"+Tooltip);
}
else
{
System.out.println("No Tool tip text present");
}
}
}
2.Selenium WebDriver and DropDown Boxes
In web application we see many drop down lists for many input fields (Ex
: gender, age, country..etc). This drop down option is different from
normal text/numeric input field. It has separate tag
<select></select>in html.
In automation while filling most of the forms we need to fill/select the
drop down values also. For achieving this WebDriver has separate class
called "Select".
In this post we will see how to select value from dropdown list.
Consider below example :
The
example code below shows the variety of methods we can use to control a
selectbox. We can also determine if we have to control a
multi-selectbox or what the first selected element is. - See more at:
http://selenium.polteq.com/en/controlling-a-selectbox-or-dropdownbox-with-selenium-webdriver/#sthash.vyb2U11G.dpuf
The
example code below shows the variety of methods we can use to control a
selectbox. We can also determine if we have to control a
multi-selectbox or what the first selected element is. - See more at:
http://selenium.polteq.com/en/controlling-a-selectbox-or-dropdownbox-with-selenium-webdriver/#sthash.vyb2U11G.dpuf
HTML CODE
<select id="city">
<option value="Op1">Chennai</option>
<option value="Op2">Hyderabad</option>
<option value="Op3">Bangalore</option>
</select>
WebElement select = driver.findElement(By.id("selection"));
List<WebElement> options = select.findElements(By.tagName("option"));
for (WebElement option : options)
{
if("Chennai".equals(option.getText()))
{
option.click();
}
}
3.How to read data from excel sheet in selenium webdriver
In Selenium WebDriver I wrote code to read the login credentials and values from the excel sheet by using Data Provider. It runs through the first set up data(login functionality) perfectly giving me the green status bar.
FileInputStream f = new FileInputStream("D:\\Selenium\\Selenium
Project\\data\\data.xls");
Workbook wb = Workbook.getWorkbook(f);
Sheet sh = wb.getSheet(3);
for(int rows=0;rows<sh.getRows();rows++)
{
for(int cols=0;cols<sh.getColumns();cols++)
{
System.out.println(sh.getCell(cols, rows).getContents().trim());
}
}
Workbook wb = Workbook.getWorkbook(f);
Sheet sh = wb.getSheet(3);
for(int rows=0;rows<sh.getRows();rows++)
for(int cols=0;cols<sh.getColumns();cols++)
System.out.println(sh.getCell(cols, rows).getContents().trim());
}
}
4.How can we get exact time to load a page using selenium webdriver
If you trying to find out how much time does it take to load a page completely using selenium webdriver. Normally web driver should return control to your code only after the page has loaded completely. So this code may help you to find the time for a page load.
Using this below code:
|
|
5.How to find repeated value in dropdown list using selenium webdriver
It is just an ordinary operation like selecting any other type of element on a webpage. You can choose it by ID, Name, Css & Xpath etc. But to perform any action on this element it is required to import ‘
Use this Code:
Select dropDown = new Select(driver.findElement(By.id("sample")));
List<WebElement> elementCount = dropDown.getOptions();
System.out.println("Number of items: " + elementCount.size());
HashSet<String> optionNames = new HashSet<>();
int one = elementCount.size();
int count = 0;
for (WebElement option : elementCount)
{
optionNames.add(option.getText());
System.out.println("Number of items: " + option.getText());
if(option.getText().contains("MODBUS_2"))
{
count++;
}
System.out.println("Duplicate found : "+count);
}
System.out.println("Duplicate found : "+count);
if(count==1)
{
System.out.println("One value only present : "+count);
}
else
{
System.out.println("Number of value present : "+count);
}
import org.openqa.selenium.support.ui.Select'
package and to use it we need to create a new Select Object of class Select.Use this Code:
Select dropDown = new Select(driver.findElement(By.id("sample")));
List<WebElement> elementCount = dropDown.getOptions();
System.out.println("Number of items: " + elementCount.size());
HashSet<String> optionNames = new HashSet<>();
int one = elementCount.size();
int count = 0;
for (WebElement option : elementCount)
{
optionNames.add(option.getText());
System.out.println("Number of items: " + option.getText());
if(option.getText().contains("MODBUS_2"))
{
count++;
}
System.out.println("Duplicate found : "+count);
}
System.out.println("Duplicate found : "+count);
if(count==1)
{
System.out.println("One value only present : "+count);
}
else
{
System.out.println("Number of value present : "+count);
}