简体   繁体   English

无法单击上下文菜单 - 在 selenium Java 中的新 window 中打开链接

[英]Not able to Click on context Menu - Open link in new window in selenium Java

enter image description here **Right click is working but not able to click on Open link in new window option.在此处输入图像描述**右键单击有效,但无法单击新 window 选项中的打开链接。 ** **

public static void newwindow() throws InterruptedException {
        System.setProperty("webdriver.chrome.driver",
                "C:\\Users\\TechExtensor\\Downloads\\chromedriver_win32\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.get("https://www.selenium.dev/documentation/webdriver/browser/windows/");
        Thread.sleep(3000);
        Actions actions = new Actions(driver);
        WebElement elementLocator = driver.findElement(By.xpath("//*[@id=\"main_navbar\"]/ul/li[3]/a/span"));
        actions.moveToElement(elementLocator);
        Thread.sleep(2000);
actions.contextClick(elementLocator).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build().perform();
    }

Use Robot class.使用机器人 class。

    Actions actions = new Actions(driver);
    WebElement elementLocator = driver.findElement(By.xpath("//*[@id=\"main_navbar\"]/ul/li[3]/a/span"));
    actions.contextClick(elementLocator).perform();
    Thread.sleep(1000);

    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.keyPress(KeyEvent.VK_ENTER);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何强制 Selenium 在新窗口中打开链接? - How to force Selenium to open a link in a new window? 如何右键单击链接并使用 Selenium 至 Java 在新选项卡中打开链接 - How to right click on a link and open the link in a new tab using Selenium through Java 如何使用 Selenium Java 单击应在同一窗口中打开的链接 - How to click on a link which should be open in same window using Selenium Java 如何在Java中使用Selenium在菜单中的新选项卡中打开一个链接 - How to open one by one link in new Tab from Menu using Selenium in Java Selenium,打开新窗口 - Selenium, open new window 无法使用Selenium Webdriver(Java)单击“确认电子邮件”链接 - Not able to click on “Confirm Email” link using selenium webdriver (Java) 在上下文菜单项上显示弹出窗口,单击Java fx - Display pop up window on context menu item click Java fx Selenium Java打开新窗口,关闭它,再次控制主窗口 - Selenium Java open new window, close it, and control main window again 在Chrome中打开新标签页(不在新标签页中链接),并专注于此 - open new tab(not link in new tab) in Chrome and focus on it Selenium java 如何单击新标签中的打开链接以使用 selenium webdriver 在主标签中显示的新标签中打开链接 - How to click on open link in new tab to open the link in new tab that appears in main tab using selenium webdriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM