Selenium 3.x双击不起作用 [英] Selenium 3.x double click not working
本文介绍了Selenium 3.x双击不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Firefox版本:52.0.2(32位)
平台:Windows 7-64位
Selenium Webdriver版本:3.4.0(Java绑定)
GeckoDriver:0.16.0
问题陈述:
Selenium 3.x无法执行双击操作.
测试代码:
Firefox Version: 52.0.2 (32 bit)
Platform: Windows 7 - 64 bit
Selenium Webdriver Version: 3.4.0 (Java bindings)
GeckoDriver: 0.16.0
Problem Statement:
Selenium 3.x is unable to perform double click operation.
Test Code:
public class GeckoTest {
public static void main(String[] args) throws IOException {
System.setProperty("webdriver.gecko.driver","I:\\jetbrainsworkspace\\src\\test\\resources\\geckodriver.exe");
FirefoxBinary binary = new FirefoxBinary(new File("D:\\installations\\browsers\\ff\\52.0.2_32\\firefox.exe"));
FirefoxOptions options = new FirefoxOptions();
options.setBinary(binary);
options.setLogLevel(Level.ALL);
WebDriver browser = new FirefoxDriver(options);
browser.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
browser.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
browser.get("https://examples.sencha.com/extjs/6.0.1/examples/classic/ticket-app/index.html");
WebDriverWait wait = new WebDriverWait(browser,20,3000);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("password"))).sendKeys("sometext");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//span[text()='Login']"))).click();
WebElement ele = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//div[text()='Fiant adipiscing clari nunc molestie per placerat vero insitam; ullamcorper saepius etiam claritatem quod.']")));
Actions builder = new Actions(browser);
builder.doubleClick(ele).build().perform();
browser.close();
}
}
手动步骤
- 导航至 EXTJ链接
- 使用任何密码登录.
- 在右侧,您会找到一张门票表.
- 如果双击任何一张票证,它将打开该票证.
- Navigate to EXTJs link
- Login with any password.
- On the right hand side you will find a table of tickets.
- If you double click on any one ticket that then it will open that ticket.
推荐答案
To overcome problems with doubleclicking in Selenium try Alternative workaround Source
简化为此:
((JavascriptExecutor) driver).executeScript("document.getElementById('map_container').dispatchEvent(new Event('dblclick'));");
这篇关于Selenium 3.x双击不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文