XpathAxes Synchronization WebElement
XpathAxes Synchronization WebElement
1. Ancestor
2. Siblings
a. Following-sibling Axis
b. Preceding-sibling Axis
Ancestor Axis:
The ancestor axis selects the common parent (parent,
grandparent, great-grandparents, etc.) of the current
node.
Syntax: /ancestor::tagname
Siblings:
following-sibling:
1.Implicitly wait :
It is a selenium wait which is used to match the
selenium speed with application speed.
Syntax:
driver.manage().timeouts().implicitlyWait(Duration,
TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(20,
TimeUnit.SECONDS);
Explanation:
• It will search for the element in HTML tree
Structure.
• If Element is found it will returns the address
• If Element is not found it will check for the given
time.
• If the given time is not over it will internally wait
for 0.5 seconds which is called Polling Period
• If the given time is over, it will throw No such
element Exception
• This process repeats
1. Until the element is found
2. Until the given time is over
Drawbacks:
It is applicable only for findElement() and
findElements().
Explanation:
It will search for the element in HTML tree Structure.
If Element is found it will returns the address
If Element is not found it willcheck for the given time.
If the given time is not over it will internally wait for
0.5 seconds which is called Polling Period
If the given time is over, it will throw TimeOut
Exception
This process repeats
1. Until the element is found
2. Until the given time is over
3.Thread.sleep
• It is java wait
• It is applicable for only particular line
• Syntax: Thread.Sleep()
WebElements:
• It is an interface in selenium which contains 3
types abstract methods.
action()
getter()
Verification()
action():
sendKeys(): which is used send the data.
clear(): which is used to clear data
click():which is used to click the webelement.
Submit(): which is used to submit (nothing but a
click). We will use this only whenever we have a type
=submit in html tree structure.
Script:
package WebElements;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
textField.clear();
Thread.sleep(5000);
driver.close();
}
}
Open the browser enter the Url of www.amazon.in
Type computers and wait for 5 seconds and clear the
data.
getter():
getText():used to get the value.
getAttribute(): It is used to get the attribute value
when we pass the attribute name as an argument.
getLocation():used to get X and Y coordinates of an
element. Return type is point
getSize(): used to get the height and width of an web
element. Return type is dimension
package WebElements;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
Verification():
isDisplayed()--->to check the element is displayed or
not. Return type is Boolean
WebElement ele =
driver.findElement(By.id("twotabsearchtextbox"));
if (ele.isDisplayed())
{
System.out.println("Pass");
ele.sendKeys("phone");
}
else
{
System.out.println("Fail");
}
driver.close();
}
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SEC
ONDS);
WebElement button =
driver.findElement(By.name("login"));
if (button.isEnabled())
{
System.out.println("Pass: element is enabled");
button.click();
}
else
{
System.out.println("Fail: element is not
enabled");
}
driver.close();
}
Navigation API:
Traversing from one page to another page is called as
Navigation API.
API --->Application Programming interface
back--->diver.navigate().back();
farward()---> diver.navigate().forward();
refresh()----> diver.navigate().refresh();
navigate().to() ---->used to navigate from one website
to another website.
driver.navigate().to(“url”);