not able to select option open link in new tab in

2019-02-21 06:18发布

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.

1条回答
Root(大扎)
2楼-- · 2019-02-21 06:44

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.

Here is the code

        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();
查看更多
登录 后发表回答