The below code will show you how to hover on an item (Logout WordPress blog).
Test steps:
- Go to http://localhost/selenium-digitest/wp-login.php
- Enter username: “admin”
- Enter password: “123456”
- Click Login
- Hover on admin main bar at top
- Select Log out.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
package Digitest; import org.junit.*; import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Actions; public class hoverLogout { private WebDriver driver; private String baseUrl; @Before public void setUp() throws Exception { driver = new FirefoxDriver(); baseUrl = "http://localhost/"; } @Test public void testOut() throws Exception { driver.get(baseUrl + "/selenium-digitest/wp-login.php"); driver.findElement(By.id("user_login")).clear(); driver.findElement(By.id("user_login")).sendKeys("admin"); driver.findElement(By.id("user_pass")).clear(); driver.findElement(By.id("user_pass")).sendKeys("123456"); driver.findElement(By.id("wp-submit")).click(); // Hover on admin main bar at top & click option "Log Out". WebElement element = driver.findElement(By.xpath(".//*[@id='wp-admin-bar-my-account']/a/img")); Actions action = new Actions(driver); action.moveToElement(element).perform(); Thread.sleep(3000); WebElement subElement = driver.findElement(By.linkText("Log Out")); action.moveToElement(subElement); action.click(); action.perform(); } @After public void tearDown() throws Exception { driver.quit(); } } |
Recent Comments