Verify Element Present or Not:: Step 1) Convert Web Driver Object To Takescreenshot
Verify Element Present or Not:: Step 1) Convert Web Driver Object To Takescreenshot
Verify Element Present or Not:: Step 1) Convert Web Driver Object To Takescreenshot
if(driver.findElements(By.linkText("REGISTER")).size()!=0){
{
System.out.println("element is present");
}
else{
if(driver.findElement(By.linkText("REGISTER")).isEnabled()){
System.out.println("Element is Enable");
}else{
System.out.println("Element is Disabled");
}
File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);
driver.switchTo().alert().dismiss();
driver.switchTo().alert().accept();
driver.switchTo().alert().getText();
driver.switchTo().alert().sendKeys("Text");
Scenario:
Step 1) Launch the web browser and open the site
driver.get("http://demo.guru99.com/test/delete_customer.php");
driver.findElement(By.name("cusid")).sendKeys("53920");
Step 3) After entering the customer ID, Click on the "Submit" button.
driver.findElement(By.name("submit")).submit();
Step 4) Reject/accept the alert.
// Switching to Alert
Alert alert = driver.switchTo().alert();
// Accepting alert
alert.accept();
In selenium web driver there are methods through which we can handle multiple
windows.
Driver.getWindowHandles();
Driver.getWindowHandle();
Now, we will automate the given below scenario to see how to handle multiple
windows using Selenium Webdriver.
driver.get("http://demo.guru99.com/popup.php");
When the user clicks on the "Click Here" link, new child window opens.
driver.findElement(By.xpath("//a[contains(text(),'Click Here')]")).click();
A new window opens, ask the user to enter email id and submit the page.
String MainWindow=driver.getWindowHandle();
// To handle all new opened window.
Set<String> s1=driver.getWindowHandles();
Iterator<String> i1=s1.iterator();
while(i1.hasNext())
{
String ChildWindow=i1.next();
if(!MainWindow.equalsIgnoreCase(ChildWindow))
{
driver.findElement(By.name("emailid")).sendKeys("sujatajalkote@gmail.com");
driver.findElement(By.name("btnLogin")).click();
driver.close();
}
}
An RGBA color value is specified with: rgba(red, green, blue, alpha). The alpha
parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque).
Not only it makes this difficult to identify the element but also if the element is not
located it will throw an "ElementNotVisibleException" exception. Using Waits, we
can resolve this problem.
2. Implicit wait:
The implicit wait will tell to the web driver to wait for certain amount of
time before it throws a "No Such Element Exception". The default setting
is 0. Once we set the time, web driver will wait for that time before
throwing an exception.
driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;
Implicit wait will accept 2 parameters, the first parameter will accept
the time as an integer value and the second parameter will accept the time
measurement in terms of SECONDS, MINUTES, MILISECOND,
MICROSECONDS, NANOSECONDS, DAYS, HOURS, etc.
3. Explicit wait:
The explicit wait is used to tell the Web Driver to wait for certain
conditions (Expected Conditions) or the maximum time exceeded before
throwing an "ElementNotVisibleException" exception.
The explicit wait is an intelligent kind of wait, but it can be applied only for
specified elements. Explicit wait gives better options than that of an
implicit wait as it will wait for dynamically loaded Ajax elements.
Once we declare explicit wait we have to use "ExpectedCondtions" or we
can configure how frequently we want to check the condition using Fluent
Wait.
WebDriverWait is a class.
4. Fluent wait:
The fluent wait is used to tell the web driver to wait for a condition, as
well as the frequency with which we want to check the condition before
throwing an "ElementNotVisibleException" exception.
Frequency: Setting up a repeat cycle with the time frame to
verify/check the condition at the regular interval of time