使用硒无法在右键单击的新选项卡中选择选项打开链接 [英] not able to select option open link in new tab in right click using selenium

查看:81
本文介绍了使用硒无法在右键单击的新选项卡中选择选项打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要:在新标签页中链接未打开.

Summary : Link is not getting open in new tab.

这是我的真实网址代码:-

Here is my code with the real url :-

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.navigate().to("https://us.justdial.com/NY/New-York/Afghani-Restaurants/ct-16110200");
WebElement rightclickelement = driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/section/div[5]/div[2]/div[2]/ul/li[1]/div/div[2]/h2/a"));
Actions action = new Actions(driver);
action.moveToElement(rightclickelement);
action.contextClick(rightclickelement).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build().perform();

预期:链接应在新标签页中打开.

Expected : Link should get open in new tab.

实际:链接会在当前标签页中打开,而不是在新标签页中打开.

Actual : Link gets open in current tab instead of new tab.

推荐答案

首先,卸载现有的Fire fox并删除配置文件,然后安装Firefox的ESR版本,必须安装ESR版本!要获得ESR版本,只需在Google中键入Firefox ESR,即可为您安装文件铺平道路.

First off, uninstall the existing Fire fox and delete the profile and then install the ESR version of Firefox, ESR version is must! To get the ESR version, simply type Firefox ESR in your google, that will pave the way for you to installation file.

这是代码

        FirefoxOptions foptions = new FirefoxOptions();
        foptions.setCapability("marionette", false);
        WebDriver driver = new FirefoxDriver(foptions);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.navigate().to("https://us.justdial.com/NY/New-York/Afghani-Restaurants/ct-16110200");
        WebElement rightclickelement = driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/section/div[5]/div[2]/div[2]/ul/li[1]/div/div[2]/h2/a"));
        Actions action = new Actions(driver);
        action.contextClick(rightclickelement).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build().perform();

这篇关于使用硒无法在右键单击的新选项卡中选择选项打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆