Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 硒和新标签_Python_Selenium_Webdriver - Fatal编程技术网

Python 硒和新标签

Python 硒和新标签,python,selenium,webdriver,Python,Selenium,Webdriver,如何在SeleniumWebDriver(firefox)的新选项卡上打开链接 驱动程序。按\u id(“测试”)查找\u元素。\u。单击() 目前看来,您最好的选择是在页面中插入锚定标记。您需要将其适应python,但它应该相对简单:package com.crm.qa.BaseTest; 导入java.awt.AWTException; 导入java.awt.Robot; 导入java.awt.event.KeyEvent; 导入java.util.ArrayList; 导入org.ope

如何在SeleniumWebDriver(firefox)的新选项卡上打开链接


驱动程序。按\u id(“测试”)查找\u元素。\u。单击()

目前看来,您最好的选择是在页面中插入锚定标记。您需要将其适应python,但它应该相对简单:

package com.crm.qa.BaseTest;
导入java.awt.AWTException;
导入java.awt.Robot;
导入java.awt.event.KeyEvent;
导入java.util.ArrayList;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.chrome.ChromeDriver;
公共类新数据库{
公共静态void main(字符串[]args)引发AWTException{
System.setProperty(“webdriver.chrome.driver”,
“C:/Users/sunil/Downloads/chromedriver_win32(2)/chromedriver.exe”);
WebDriver驱动程序=新的ChromeDriver();//打开浏览器
driver.manage().window().maximize();//浏览器最大化
驱动程序。获取(“http://www.google.com“”;//打开谷歌
//打开新选项卡
对于(int i=0;i
<a href='/test' id='test'>Link</a>

driver.find_element_by_id('test').click()
package com.crm.qa.BaseTest;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class NewTabChrome {

    public static void main(String[] args) throws AWTException {

        System.setProperty("webdriver.chrome.driver", 
                "C:/Users/sunil/Downloads/chromedriver_win32 (2)/chromedriver.exe");

        WebDriver driver = new ChromeDriver();//open browser
        driver.manage().window().maximize();//browser maximize
        driver.get("http://www.google.com");//open google 

        //open new tab 
        for(int i = 0; i<=1;i++){
        Robot rob = new Robot();
        rob.keyPress(KeyEvent.VK_CONTROL);
        rob.keyPress(KeyEvent.VK_T);
        rob.keyRelease(KeyEvent.VK_CONTROL);
        rob.keyRelease(KeyEvent.VK_T);
        ArrayList<String> tabs1 = new ArrayList<String> (driver.getWindowHandles());
        //Switch to new tab
        driver.switchTo().window((String) tabs1.get(i));
    }
        //open facebook
        driver.get("http://facebook.com");
        driver.quit();
    }
}