【问题标题】:SendKeys in firefox quantum using selenium使用硒的Firefox量子中的SendKeys
【发布时间】:2018-01-18 13:12:57
【问题描述】:

在 Firefox 量子上使用 selenium 3.5 选择 WebElement 后,我​​一直在尝试按 (CTRL + ALT + 'f')。这是我写的代码:

WebElement ele = m_driver.findElement(By.cssSelector(".tm-project-name"));
ele.click();
Actions act = new Actions(m_driver);
act.sendKeys(Keys.CONTROL).perform();
act.sendKeys(Keys.ALT).perform();
act.sendKeys("f").perform();

为了完成这项工作,我也尝试了这种方法

act.sendKeys(Keys.chord(Keys.CONTROL, Keys.ALT, "F")).build().perform();

这两种方法在 chrome 浏览器上都可以正常工作,但在 Firefox Quantum 中无法正常工作。 谁能帮我解决这个问题。

【问题讨论】:

  • 你试图通过 control+Alt+"f" 的目的是什么?
  • 而不是整个Actions act ... act.sendKeys("f").perform();部分,点击后尝试添加:ele.sendKeys(Keys.chord(Keys.CONTROL, Keys.ALT, "F"));
  • @Pradeephebbar 我需要在我的应用程序中执行此操作并突出显示一个元素。
  • @GalAbra 我也试过了,但这在 Firefox 量子中不起作用。
  • Java click() 会发生什么?你看到任何错误吗?更新问题中的错误堆栈跟踪。同时更新press (CTRL + ALT + 'f')的用途。

标签: selenium selenium-chromedriver sendkeys geckodriver firefox-quantum


【解决方案1】:

您可以尝试使用 Robot class 传递 control+Alt+"f",这将适用于所有浏览器。

试试下面的代码。

Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_F);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyRelease(KeyEvent.VK_F);

希望这对你有用。

【讨论】:

  • 这里是需要的进口......对于任何尝试的人:1)进口java.awt.Robot; 2) 导入 java.awt.event.KeyEvent;
【解决方案2】:
WebElement ele = m_driver.findElement(By.cssSelector(".tm-project-name"));
ele.send_keys(Keys.SHIFT+Keys.CONTROL+'f');

我通常用 python 编写,在提交之前我在我的 IDE 中检查了它...Python 工作...认为这是 C# 版本

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-28
    • 2013-01-11
    • 2018-08-02
    • 1970-01-01
    • 2021-08-04
    • 1970-01-01
    • 1970-01-01
    • 2017-01-16
    相关资源
    最近更新 更多