How to handle frame in selenium WebDriver?

In this article, i will talk about how to handle frame in selenium webdriver.

What is frame?

Frame is nothing but a container where few elements are grouped together. In short Frame is a HTML document within HTML document (Page). In HTML frames are also called as Iframe (Inline Frame). On HTML pages, iframes are mostly used to add content from another source (page), like advertisement.

How to Identify if frame is present on WebPage?

If you are unable to click on the element directly, please check if it is a frame. It is very simple to identify if it is a frame.
Right click on the frame. IF you see option like “This Frame” present after right click, then that is a frame & you need to handle it by switching it to that frame as explained further.

Below Image shows you how to identify frame.

On my blog : https://automationtalks.com/  My name card of LinkedIn appear as frame. refer below screenshot

If frame is there, means it should has either id or name. So that this frame id or frame name will be used to switch to this frame. Below image shows about frame id and frame name.
How to find total number of frames present on the webpage? 
Let us understand how can we find out how many frames are present on particular webpage.

As we saw earlier, the frame will have tagName “iFrame”. So we can use this tagname to find out number of frames present on the WebPage.

Get the number of frames in the list.

Example

List<WebElement> frameList=driver.findElements(By.tagName(“iframe”));
System.out.println(“Total number of frames present: ”+frameList.size());
Once we get to know about the frame, now question is how to handle this frame.

In order to deal with the elements present on the frame, first we need to switch to that respective frame. Let us see how this can be done

Scenario 1: If we know the number of frames present on the page-

If you know about number of frames present on the webpage, and you are sure about the frame number to which you wanted to switch, we can use index number (frame number) to switch to frame.

Note that, frames index number starts from 0. This means, for first frame, index would be 0.

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.navigate().to("https://learnaboutsoftwaretesting.blogspot.in");
		
		  try {
			  
			  driver.switchTo().frame(indexnumber); //here you can enter the index number
			  
			       }
			 catch (NoSuchFrameException e)
			      {            
			  
	System.out.println(e.getMessage());     
	
		
	}

Scenario 2: if you know the frame name.

If you know the frame name, How to handle frame, we can use –

                 WebDriver driver = new FirefoxDriver();
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
		driver.manage().window().maximize();
		
		driver.navigate().to("https://learnaboutsoftwaretesting.blogspot.in");
		
		try {
			driver.switchTo().frame("frameName"); //enter the frame name here
			      } 
			 catch (NoSuchFrameException e)
			    {            
			    System.out.println(e.getMessage());     
			    }

Scenario 3: if you don’t know about number of frames and frame names.
If you are not sure about the frame id or frame name, then the only option you have is, using xpath.

WebDriver driver = new FirefoxDriver();
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
		driver.manage().window().maximize();
		
		driver.navigate().to("https://learnaboutsoftwaretesting.blogspot.in");
	
		 try {
		 
		WebElement button=driver.findElement(By.xpath(""));  
		 
		driver.switchTo().frame(button);		 
		}
		catch (NoSuchFrameException e)
		     {          
		System.out.println(e.getMessage());     
		 
		     }
Note that, once you are done with operations on the frame, you need to switch back to you main page, using defaultContent menthod.

  driver.switchTo().defaultContent();
Hope, this makes you clear about how to handle frame !!!!

How to handle multiple Check Boxes in Selenium WebDriver?

A group of check boxes is created by giving two or more checkboxes the same control name. In the above example, the checkbox group control name is “color”. However, each checkbox in the group has a different associated value specified by the value attribute.

When a user selects (checks) a checkbox, its value gets assigned as the current value of the checkbox group’s control name. A checkbox group’s control name may conceivably get paired with several current values if the user selects more than one checkbox.
Let us consider below screen which show the example of check boxes.
 
Source code for check boxes shown in above image is:
My favourite colors are:<br><br>
<input type="checkbox" name="color" value="red">
Red<br>
<input type="checkbox" name="color" value="yellow">
Yellow<br>
<input type="checkbox" name="color" value="blue">
Blue<br>
<input type="checkbox" name="color" value="orange">
Orange<br>
<input type="checkbox" name="color" value="green">
Green<br>
<input type="checkbox" name="color" value="purple"> 
Purple<br>

By observing above HTML code, we can see that, name of all the check boxes is same. So what we can do is, get the list of all check boxes by using attribute name and iterate over it. If found matching, then click on it.

Below piece of code illustrate the same. –

package learnAboutActionsClass;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class CheckBoxInSelenium {

 public static void main(String[] args) {

  
  WebDriver driver = new FirefoxDriver();
  
  driver.navigate().to("http://www.ironspider.ca/forms/checkradio.htm");
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  driver.manage().window().maximize();
  
  List<WebElement> ListOfCheckBoxes = driver.findElements(By.name("color"));
  System.out.println("Number of check boxes pesent are: "+ListOfCheckBoxes.size());
  
  for(int i=0; i< ListOfCheckBoxes.size() ; i++) {
   if(ListOfCheckBoxes.get(i).getAttribute("value").equalsIgnoreCase("Red")){
    ListOfCheckBoxes.get(i).click();
   }
       }
  
 }

}

Refer below video for same explanation –

 

Refer below post for complete example of Automation of Registration page using Selenium WebDriver.
Hope this Helps!!!

How to Handle Radio Button in Selenium WebDriver?

I think radio button I’d is dynamically generated. Try using By.name() with WebDriverWait to wait until radio button visible.

Performing radio button select operation is quite easy if you want to select the radio button without checking if any of the button is selected by default.

In most of the cases, ID attribute of the radio button will serve purpose, since ID attribute will be different for each radio button. Note that, most of the time, name will be same for all radio buttons of specific field. So, if you wanted to use list & check if any of the button is selected, you can use name attribute.

Let us consider below example. –

As shown on above screen shot, there are 2 radio buttons, let us see, how can we select them.
Below is the HTML code for these radio buttons.

<div class="radio-inline">
<label class="top" for="id_gender1">
<div id="uniform-id_gender1" class="radio">
<span>
<input id="id_gender1" type="radio" value="1" name="id_gender">
</span>
</div>
Mr. 
</label>
</div>
<div class="radio-inline">
<label class="top" for="id_gender2">
</div>
</div>
So, as you can see, ID attribute for each radio button is different, we can use it for selection. Lets see how to do this.

                String gender = "female";
  WebElement RadioButtonMr = driver.findElement(By.xpath("//*[@id='id_gender1']"));
  WebElement RadioButtonMrs = driver.findElement(By.xpath("//*[@id='id_gender2']"));
  
  if (gender.equalsIgnoreCase("male")){
   RadioButtonMr.click();
  }
  if (gender.equalsIgnoreCase("Female")){
   RadioButtonMrs.click();
  }

Above code is a very simple approach how can we select radio button.

Another way to select the radio buttons is by using the value attribute.

 Let us see, how this can be achieved.

As we saw earlier, name attribute will be same for radio buttons. So, what we can do is, get the list of radio buttons by unique name and iterate on it.
String valueOfGender = "2"; //in this case, value is integer, it can be String in most of the cases. 
List<WebElement> RadioButtonList = driver.findElements(By.name("id_gender"));
  System.out.println("Total numer of Radio Buttons for gender field is: " +RadioButtonList.size());
  
  for (int i = 0; i < RadioButtonList.size(); i++){
   String gend = RadioButtonList.get(i).getAttribute("value");
   if (gend.equalsIgnoreCase((valueOfGender))){
    RadioButtonList.get(i).click();
    break;
   }
   
  }

Refer below post for complete example of Automation of Registration page using Selenium WebDriver.

Refer below video –

Hope this helps !!!

How to handle dropdown in selenium WebDriver?

 Two ways to handle dropdown –

         1.      Using Select class
The big secret to working with drop down is that you don’t want to work with them as WebElements, but instead create a Select element for them. The Select class (java and python documentation) includes utility methods that allow you to perform common tasks. We will be working with the following html:
<select id="id_state" class="form-control" name="id_state" style="">
<option value="">-</option>
<option value="1">Alabama</option>
<option value="2">Alaska</option>
<option value="3">Arizona</option>
<option value="4">Arkansas</option>
<option value="5">California</option>
<option value="6">Colorado</option>
<option value="7">Connecticut</option>
<option value="8">Delaware</option>
In order to deal with dropdown values through selenium WebDriver, Selenium has Select class. (org.openqa.selenium.support.ui.Select;).
We can select value from dropdown, by below simple steps.
Firstly, Identify WebElement with Select tag, that is for your dropdown.
Ex –                  WebElement element = driver.findElement(By.id(” “));
Then, create an object of Select class.
Ex.                     Select s = new Select(listbox);
Then Select the value by one of the applicable methods like ByVisibleText, ByIndex ….whichever can be applied.
    selectByIndex
WebElement element = driver.findElement(By.id("mySelectID")); 
Select s= new Select(element);
s.selectByIndex(0);
    selectByValue
WebElement element = driver.findElement(By.id("mySelectID")); 
Select s= new Select(element);
s.selectByValue("Value");
     selectByVisibleText
WebElement element = driver.findElement(By.id("mySelectID"));
Select s= new Select(element);
s.selectByVisibleText("Option");
           
        2.       Without Using Select class
We can deal with dropdown value without using select class as well. Below are two examples how this can be achieved.


Method 1:

In this example, we find the option via a complex xpath, then click on it:

WebElement myoption = driver.findElement(By.xpath(
    "//Select[@id='mySelectID']/option[normalize-space(text())='Option']")

);
 myOption.click();

Method 2:

In this example, we find all the options, iterate over them, and click the one we want. This is useful if you have some more complex criteria.


WebElement mySelectElm = driver.findElement(By.id("mySelectID")) 
Select mySelect= new Select(mySelect);
List<WebElement> options = mySelect.getOptions();
for (WebElement option : options) {
    if (option.getText().equalsIgnoreCase("Option") {

        option.click();

    }

}

This is all about Selecting dropdown. However, note that, method 1 is more recommended, that is by using Select class.

Refer below post for complete example of Automation of Registration page using Selenium WebDriver.

Refer below video on same –

Hope This Helps !!!!!

How to Automate Registration page using Selenium WebDriver?

In this article, let us talk about how to Automate Registration page. In earlier posts, we saw, how to select value from dropdown, how to select check boxes, how to send value to field etc. Now let us try all in one example. Here is an example of Automation of registration page using Selenium WebDriver.

Refer below post to know how to handle check boxes using selenium WebDriver.
Refer below post to know how to select radio button using selenium WebDriver.
Refer below post to know how to handle dropdown in selenium WebDriver.
URL used for this example:  http://automationpractice.com/index.php
Below code shows the complete code of automate registration page.
package learnAboutActionsClass;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;


public class AutomateRegistrationPage {

 public static void main(String[] args) {

  WebDriver driver = new FirefoxDriver();
  
  //navigate to URL
  driver.navigate().to("http://automationpractice.com/index.php");
  
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  driver.manage().window().maximize();
  
  driver.findElement(By.xpath("//*[@id='header']/div[2]/div/div/nav/div[1]/a")).click();
  
  driver.findElement(By.xpath("//*[@id='email_create']")).sendKeys("testtest123@gmail.com");
  driver.findElement(By.xpath("//*[@id='SubmitCreate']")).click();
  
  //Select Radio Button
  String valueOfGender = "2"; //in this case, value is integer, it can be String in most of the cases.
  
  List<WebElement> RadioButtonList = driver.findElements(By.name("id_gender"));
  
  System.out.println("Total numer of Radio Buttons for gender field is: " +RadioButtonList.size());
  
  for (int i = 0; i < RadioButtonList.size(); i++){
   String gend = RadioButtonList.get(i).getAttribute("value");
   if (gend.equalsIgnoreCase((valueOfGender))){
    RadioButtonList.get(i).click();
    break;
   }
   
  }
  
  //Enter customer details
  driver.findElement(By.xpath("//*[@id='customer_firstname']")).sendKeys("FirstName");
  driver.findElement(By.xpath("//*[@id='customer_lastname']")).sendKeys("lastName");
  driver.findElement(By.xpath("//*[@id='passwd']")).sendKeys("Password@123");
  
  //Select date of Birth
  Select sDate = new Select(driver.findElement(By.xpath("//*[@id='days']")));
  sDate.selectByVisibleText("2  ");
  
  Select sMonth = new Select(driver.findElement(By.xpath("//*[@id='months']")));
  sMonth.selectByVisibleText("May ");
  
  Select sYear = new Select(driver.findElement(By.xpath("//*[@id='years']")));
  sYear.selectByVisibleText("2015  ");
  
  //select required check boxes
  String newsLetterReq = "Yes";
  if (newsLetterReq.equalsIgnoreCase(newsLetterReq)){
  driver.findElement(By.xpath(".//*[@id='newsletter']")).click();
  }
  
  String reciveSpclOffer = "Yes";
  if (reciveSpclOffer.equalsIgnoreCase(reciveSpclOffer)){
   driver.findElement(By.xpath("//*[@id='optin']")).click();
   
   
  //Fill address related details
  driver.findElement(By.xpath("//*[@id='firstname']")).sendKeys("FnameInAddr");
  driver.findElement(By.xpath("//*[@id='lastname']")).sendKeys("LnameinAddr");
  driver.findElement(By.xpath("//*[@id='company']")).sendKeys("comp");
  driver.findElement(By.xpath("//*[@id='address1']")).sendKeys("addr1");
  driver.findElement(By.xpath("//*[@id='address2']")).sendKeys("addr2");
  driver.findElement(By.xpath("//*[@id='city']")).sendKeys("Pune");
  
  Select sState = new Select(driver.findElement(By.xpath("//*[@id='id_state']")));
  sState.selectByVisibleText("Alabama");
  
  driver.findElement(By.xpath("//*[@id='postcode']")).sendKeys("12345");
  
  Select sCountry = new Select(driver.findElement(By.xpath("//*[@id='id_country']")));
  sCountry.selectByVisibleText("United States");
  
  driver.findElement(By.xpath("//*[@id='other']")).sendKeys("any other info");
  driver.findElement(By.xpath("//*[@id='phone']")).sendKeys("123457876");
  driver.findElement(By.xpath("//*[@id='phone_mobile']")).sendKeys("868768768768");
  driver.findElement(By.xpath("//*[@id='alias']")).sendKeys("alias");
  
  driver.findElement(By.xpath("//*[@id='account-creation_form']")).click();
   
   
  }
  
 }

}

Post your questions / suggestions.

What is actions class in Selenium WebDriver?

Actions class in Selenium WebDriver –

In Webdriver, handling keyboard events and mouse events (including actions such as Drag and Drop or clicking multiple elements With Control key) are done using the advanced user interactions API . It contains Actions and Action classes which are needed when performing these events.

In order to perform action events, we need to use org.openqa.selenium.interactions.Actionsclass.
We need to use perform() to execute the action.
Using Action API, keyboard interactions are simple to do with webdriver. In Advanced User Interactions API, interaction with element is possible either by clicking on element or sending a Keys using sendKeys()
To use mouse actions, we need to use current location of the element and then perform the action.
The following are the regularly used mouse and keyboard events:
Method :clickAndHold()
Purpose: Clicks without releasing the current mouse location

Method : contextClick()
Purpose: Performs a context-click at the current mouse location (double click).

Method: doubleClick()
Purpose: Performs a double click at the current mouse location

Method: dragAndDrop(source,target)
Parameters: Source and Target
Purpose: Performs click and hold at the location of the source element and moves to the location of the target element then releases the mouse.

Method : dragAndDropBy(source,x-offset,y-offset)
Parameters: Source, xOffset – horizontal move, y-Offset – vertical move Offset
Purpose: Performs click and hold at the location of the source element moves by a given off set, then releases the mouse.

Method: keyDown(modifier_key)
Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONROL)
Purpose: Performs a modifier key press, doesn’t release the modifier key. Subsequent interactions may assume it’s kept pressed

Method: keyUp(modifier_key)
Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONROL)
Purpose: Performs a key release.

Method: moveByOffset(x-offset, y-offset)
Parameters: X-Offset , Horizontal offset, a negative value means moving the mouse to left side.
Y-Offset, vertical offset, a negative value means moving the mouse to up.
Purpose: Moves the mouse position from its current position by the given offset.

Method: moveToElement(toElement)
Parameters: toElement – Element to Move to
Purpose: It moves the Mouse to the middle of the element.

Method: release()
Purpose: It releases the left mouse button at the current mouse location.

Method: sendKeys(onElement, charSequence)
Parameters: onElement, which will receive the keyStrokes, usually text field.
charsequence- any string value representing the sequence of keyStrokes to be sent.
Purpose: It sends a series of keyStrokes onto the element

As mentioned above, we can use Actions class for following actions –

Hope This helps !!!

MouseHover action in selenium WebDriver

Mousehover action in selenium WebDriver –

In the Actions class, the user, can perform one action, by simply calling it into the driver instance, followed by the method perform().

MouseHover using Actions Class in Selenium WebDriver

Let us see about mousehover action in selenium. If the menu bar or anywhere on the page, the menu has dropdown, and the dropdown options appear only when you hover the mouse on that menu.

So, in this case, we can use mouse hover action of the Actions class in selenium

Let us see, hot this can be achieved.

In my blog (URL: http://automationtalks.com/), suppose you want to select the sub-menu (Selenium WebDriver) of Menu: Selenium.

See below screen.
MouseHover using Actions Class in Selenium WebDriver
To Achieve this, follow below mentioned steps.
  1. Open the browser.
2.    Navigate to the given URL (http://automationtalks.com/).
  1. Mouse Hover on “Selenium Tutorial” tab present in the top navigational bar.
  2. Select the Menu which you want to click on (let us consider here as – “Selenium WebDriver”.
  3. Click on the “Selenium WebDriver”.
  4. Close the browser.
First define actions class –

                        Actions act = new Actions(driver);

Then, mousehover using actions class, syntax below –

act.moveToElement(driver.findElement(“webelement_Menu_location”)).build().perform();

Now, the submenu should be visible, Then click on the submenu –

driver.findElement(“WebElement_submenu”).click();

Below is the example how can be mouse hover achieved in selenium WebDriver.

package demoPackage1;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;

public class ActionsClass {
  
  @Test
  public void TestCase() throws InterruptedException{
    
    System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    
    driver.navigate().to("http://automationtalks.com/");
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    
    Actions act = new Actions(driver);

    //Define actions class & move to webelement  (Hove mouse to webelement)
    act.moveToElement(driver.findElement(By.xpath("//span[contains(.,'Selenium Tutorial')]"))).build().perform();
    
    //After mouse hover, element form dropdown is appeared, then click on it.
    driver.findElement(By.xpath("//a[contains(.,'Selenium WebDriver')]")).click();
    
    Thread.sleep(3000);
    
    
    driver.close();
    driver.quit();
    
    

    
  }

}

Hope This Helps !!!!

Right Click (Context Click) in Selenium

Right click or Context click in selenium WebDriver using Actions class-

Sometimes you’ll run into an app that has functionality hidden behind a right-click menu (a.k.a. a context menu). These menus tend to be system level menus that are untouchable by Selenium. So how do you test this functionality?

Right Click (Context Click ) using Actions Class using Selenium WebDriver
We can then select an option from the menu by traversing it with keyboard arrow keys (which we can issue with the Action Builder’s send_keys command).
In Selenium WebDriver to perform right click on any web element is not a complex process. All you have to do is create an instance of Action class and call the methods defined in it to perform the actions you want. Follow the below steps in order to perform right click on any web element:

Below are the Steps we have followed in the example:

    Identify the element
    Wait for the presence of Element
    Now perform Context click
    After that we need to select the required link.

Example –

package learnAboutActionsClass;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class RightClickInSelenium {
 
 public static void main(String[] args){
  
  WebDriver driver = new FirefoxDriver();
  driver.navigate().to("http://automationtalks.com/");
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  driver.manage().window().maximize();
  
  Actions act = new Actions(driver);
  act.moveToElement(driver.findElement(By.xpath("//*[@id='mbtnav']/li[3]/a"))).build().perform();
   act.contextClick(driver.findElement(By.xpath("//*[@id='mbtnav']/li[3]/ul/li[2]/a"))).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build().perform();
  //Switching between tabs using CTRL + tab keys.
    driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");
    //Switch to current selected tab's content.
    driver.switchTo().defaultContent();  
 }

}

Here the method sendKeys(Keys.ARROW_DOWN) is used to select an option from the list. If you will not add this method, the right click on the web element will be performed and the option list which appears after the right click will get disappeared without selecting any option.

We can perform the right click on any web element using the Robot class too. Here you first need to move the mouse to the particular web element and then perform the required action…!!!

Actions class in Selenium WebDrivr

How to Verify ToolTip text using Selenium WebDriver?

What is ToolTip Text Message?

ToolTip message is the hint to GUI user. Below Screenshot shows ToolTip message.

There are two ways to read and verify tooltip message.

Verify ToolTip  text using Actions Class in Selenium WebDriver

1. Using Actions class

Whenever you focus on element and a tool-tip appears it is displayed inside a “div” which is made visible on mouse focus.

  1. Move to element using actions classActions action = new Actions(driver); action.moveToElement(‘element_to_be_focused’).build().perform();
  1. Now since tooltip displays some text, read that text and find out element from page source HTML where it is mentioned.
  2. Now simply write code to wait for visibility of element having tooltip text.
new WebDriverWait(driver, timeOutInSeconds).until(ExpectedConditions.visibilityOfElementLocated(‘element_locator’));
  1. Get text from tooltip element using getText()
 Below is sample code  –
package learnAboutActionsClass;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class VerifyToolTipMessage {

 public static void main(String[] args) {

  WebDriver driver = new FirefoxDriver();
  driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
  driver.manage().window().maximize();
  
  driver.get("https://jqueryui.com/tooltip/");
  driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@class='demo-frame']")));
  
  new Actions(driver).moveToElement(driver.findElement(By.xpath("//input[@id='age']"))).build().perform();
  
  boolean isToolTipDisplayed = driver.findElement(By.xpath("//div[@class='ui-tooltip-content']")).isDisplayed();
  
  if (isToolTipDisplayed) {
  
   String tooltipText = driver.findElement(By.xpath("//div[@class='ui-tooltip-content']")).getText();
  System.out.println("Tooltip Text:- " + tooltipText);
  }
  driver.switchTo().defaultContent();
  
  driver.quit();
  
 }

}

2. Using “title” Attribute 

Whenever you will have tooltip then “title” attribute will be there

  package learnAboutActionsClass;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class VerifyToolTipMessage1 {

 public static void main(String[] args) {

  WebDriver driver = new FirefoxDriver();
  
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  driver.manage().window().maximize();
  driver.navigate().to("https://learnaboutsoftwaretesting.blogspot.in");
  String ToolTipText = driver.findElement(By.xpath(".//*[@id='mbtnav']/li[1]/a")).getAttribute("title");
  System.out.println("ToolTip message is: "+ToolTipText);
  driver.quit();
 }

}

Refer below links to learn more about Actions Class in Selenium WebDriver –

Hope this helps !!!

Difference between click and submit methods in Selenium webdriver?

In this article, i will talk about difference between click and submit method. Submit is for Forms and Click is for Buttons

If you submit using any element of Form, it will automatically find button with type ‘submit’ of form and click on it.

Submit can be done on any form item and click has to be done Button with type Submit

Both click() and submit() both are used to click Button in Web page.

Selenium WebDriver has one special method to submit any form and that method name Is submit(). submit() method works same as clicking on submit button.

.click() method :
You can use .click() method to click on any button. There is no restriction for click buttons.
That means element’s type = “button” or type = “submit”, .click() method will works for both.
If button is inside <form> tag or button is outside <form> tag, the click() method will work.

.submit() method :
we can use .submit() method for only submit form after click on button.
That means element’s type = “submit” and button should be inside <form> tag, then only submit() will work.
If element’s type = “button” means submit() will not work.
If button outside of the <form> tag means submit() will not work

For Example, Submit() will work if submit button should be inside <form> tag and element type=”submit” as below

<form>
<input id="submitbutton" name="submitbutton" type="submit" value="Next step" class=

"g-button g-button-submit">
</form>

But click() method will work for all  buttons in webpage with out any restrictions.

Hope this helps !!!