在Selenium中添加鼠标操作
我看过这个网站: 我在代码顶部添加了这一行:在Selenium中添加鼠标操作,selenium,Selenium,我看过这个网站: 我在代码顶部添加了这一行: import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.interactions.Mouse; 但是当我开始键入时,Eclipse中不会出现“方法和描述”选项 我正在努力: driver.findElement(By.id("test")).clickAndHold(); 但是Eclipse中没有显示任何选项……我遗漏了什么?需要为Actions类创
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.Mouse;
但是当我开始键入时,Eclipse中不会出现“方法和描述”选项
我正在努力:
driver.findElement(By.id("test")).clickAndHold();
但是Eclipse中没有显示任何选项……我遗漏了什么?需要为Actions类创建对象,然后才能执行鼠标操作 步骤:
WebElement element driver.findElement(By.id("test"));
Actions builder=new Actions(driver);
builder.moveToElement(element).clickAndHold().build().perform();
WebElement element driver.findElement(By.id("test"));
Actions builder=new Actions(driver);
builder.moveToElement(element).clickAndHold().build().perform();
需要为Actions类创建对象,然后才能执行鼠标操作 步骤:
WebElement element driver.findElement(By.id("test"));
Actions builder=new Actions(driver);
builder.moveToElement(element).clickAndHold().build().perform();
WebElement element driver.findElement(By.id("test"));
Actions builder=new Actions(driver);
builder.moveToElement(element).clickAndHold().build().perform();
用于模拟复杂用户手势的面向用户的API。使用此类,而不是直接使用键盘或鼠标 是的,如果你想模拟鼠标、键盘动作,你必须使用actions类。 请注意,actions是类,action是Selenium中的接口 使用actions类中存在的方法,就像您必须实例化它的任何普通方法一样
Actions action = new Actions(driver);
action.click();
action.click(WebElement target)
action.contextClick() // right click
action.doubleClick()
action.dragAndDrop(WebElement source, WebElement target)
还有更多
请注意,如果只模拟一个事件,则必须使用perform()方法,这是非常不可能的,因此如果要模拟多个事件,则必须build().perform()
代码:
action.doubleClick().perform();
和:
action.clickAndHold(WebElement target).release().build().perform();
用于模拟复杂用户手势的面向用户的API。使用此类,而不是直接使用键盘或鼠标 是的,如果你想模拟鼠标、键盘动作,你必须使用actions类。 请注意,actions是类,action是Selenium中的接口 使用actions类中存在的方法,就像您必须实例化它的任何普通方法一样
Actions action = new Actions(driver);
action.click();
action.click(WebElement target)
action.contextClick() // right click
action.doubleClick()
action.dragAndDrop(WebElement source, WebElement target)
还有更多
请注意,如果只模拟一个事件,则必须使用perform()方法,这是非常不可能的,因此如果要模拟多个事件,则必须build().perform()
代码:
action.doubleClick().perform();
和:
action.clickAndHold(WebElement target).release().build().perform();