1.鼠标悬停
一般有一些下拉菜单需要鼠标放在下拉箭头才会出现,这个时候就需要鼠标悬停的操作进行下一步操作
应用:
package com.ming.Selenium.Actions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class Pause {
public static void main(String[] args) {
ChromeDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.baidu.com/");
//定位元素:设置
WebElement el = driver.findElement(By.xpath("//*[@id=\"s-usersetting-top\"]"));
//创建一个动作对象
Actions actions = new Actions(driver);
//.moveToElement(el) 移动到元素 .perform() 将动作提交
actions.moveToElement(el).perform();
//定位元素点击
driver.findElement(By.xpath("//*[@id=\"s-user-setting-menu\"]/div/a[1]/span")).click();
}
}
日后继续更·····