Send keys control + click in Selenium with Python bindings

前端 未结 6 853
甜味超标
甜味超标 2020-12-01 00:54

I need to open link in new tab using Selenium.

So is it possible to perform ctrl+click on element in Selenium to open it in new tab?

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 01:21

    Below is what i have tried for Selenium WebDriver with Java binding and its working for me. If you want to manually open the Link in New Tab you can achieve this by performing Context Click on the Link and selecting 'Open in new Tab' option. Below is the implementation in Selenium web-driver with Java binding.

    Actions newTab= new Actions(driver);
    WebElement link = driver.findElement(By.xpath("//xpath of the element"));
    
    //Open the link in new window
    newTab.contextClick(link).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build().perform();
    

    Web-driver handles new tab in the same way to that of new window. You will have to switch to new open tab by its window name.

    driver.switchTo().window(windowName);
    

    You can keep track of window-names which will help you to easily navigate between tabs.

提交回复
热议问题