Sei sulla pagina 1di 3

//*[@id="easycont"]/div/div[2]/div[1]/div[2]/button

//div[text()='Java Script Alert Box']//following::button[text()='Click


me!']//parent::div

//button[@class='btn btn-primary btn-success btn-block']

//button[@id='autoclosable-btn-success']

........................................................................

package com.techbeamers.testing;
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.interactions.Actions;

public class MouseHoverExample {

public static void main(String[] args) throws Exception {

// Initialize WebDriver
WebDriver driver = new FirefoxDriver();

// Wait For Page To Load


driver.manage().timeouts().implicitlyWait();

// Go to URL
driver.get("http://www.myntra.com/");

// Maximize Window
driver.manage().window().maximize();

// Mouse Over On " Men link "


Actions act = new Actions(driver);
By testlink = By.linkText("Men");
WebElement test = driver.findElement(testlink);
act.moveToElement(test).build().perform();

// Click on " bags & backpacks " link


driver.findElement(By.linkText("Bags & Backpacks")).click();

// Click on the categories - Bag-packs

driver.findElement(By.xpath("//*[text()='Categories']//following::li[1]/label")).cl
ick();

// Mouse Hover on the 1st bag


Actions sel = new Actions(driver);
sel.moveToElement(driver.findElement(By.xpath("//ul[@class='results
small']/li[1]"))).build().perform();

// Click on the "Add to Bag" icon of the 1st bag


driver.findElement(By.xpath("//ul[@class='results
small']/li[1]/div[1]//div")).click();

// Hover over the shopping bag icon present on the top navigation bar
Actions mov = new Actions(driver);
mov.moveToElement(driver.findElement(By.xpath("//a[contains(@class,
'cart')]//div"))).click().build().perform();

// Click on the remove icon


driver.findElement(By.xpath("(//span[@data-hint='REMOVE FROM BAG'])
[1]")).click();

// Closing current driver window


driver.close();
}
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

//driver.findElement(By.xpath("//*[contains(@href,'popup.php')]")).click();

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))
{
// Switching to Child window
driver.switchTo().window(ChildWindow);

driver.findElement(By.name("emailid")).sendKeys("gaurav.3n@gmail.com");

driver.findElement(By.name("btnLogin")).click();
// Closing the Child Window.
driver.close();
}
}
// Switching to Parent window i.e Main Window.
driver.switchTo().window(MainWindow);
}
Partial Link Test:

//strong[text()='Partial Link Test']

...........................................

Normalize-space

//button[text()[normalize-space()='Features']]
//*[@id="ShopifyMainNav"]/ul[2]/li[1]/div/button
......................................................................
https://phptravels.com/demo/

//*[@id="Popover2"]/div/ul/li[1]/a
//*[@id="Popover2"]/div/ul/li[2]/a

//*[@id="table2"]/tbody/tr[1]/td[1]

//table[@id='table1']//tbody//tr//td[text()='jsmith@gmail.com']
//nav[@id='ShopifyMainNav']//ul//li//div//following-sibling::button[text()
[normalize-space()='Features']]

Potrebbero piacerti anche