2017-01-03 1 views
0

新しいシークレットウィンドウを開く方法は?私は繰り返しは、私が新しいシークレットウィンドウを開くようにしたい終了される時意味:セレンのpythonで新しいシークレットウィンドウを開く方法

class JoinPage(unittest.TestCase): 

@classmethod 
def setUpClass(cls): 

    chrome_options = webdriver.ChromeOptions() 
    chrome_options.add_argument('--incognito') 
    chrome_options.add_argument('--start-maximized') 
    cls.browser = webdriver.Chrome('/home/andrew/Downloads/chromedriver', chrome_options=chrome_options) 

def test_01_new_account_jp(self): 
    with open('/home/andrew/PycharmProjects/test/jpage/accounts.csv', 'rb',) as csvfile: 
     the_file = csv.reader(csvfile, delimiter=',') 
     for row in the_file: 
      for i in range(2): 
       self.browser.get('http://localhost:5000') 
       user = row[0] 
       password = row[1] 
       self.browser.xpath('html/body/div[1]/div/div/div[2]/form/div[2]/div/button').click() 
       self.browser.xpath(".//*[@id='Email']").send_keys(user) 
       self.browser.xpath(".//*[@id='next']").click() 
       self.browser.xpath(".//*[@id='Passwd']").send_keys(password) 

をしかし、私はこのように私のコードを書くとき:

class JoinPage(unittest.TestCase): 


def test_01_new_account_jp(self): 
    with open('/home/andrey/PycharmProjects/test/jpage/accounts.csv', 'rb',) as csvfile: 
     the_file = csv.reader(csvfile, delimiter=',') 
     for row in the_file: 
      chrome_options = webdriver.ChromeOptions() 
      chrome_options.add_argument('--incognito') 
      chrome_options.add_argument('--start-maximized') 
      browser = webdriver.Chrome('/home/andrey/Downloads/chromedriver',chrome_options=chrome_options) 
      actions = ActionChains(browser) 
      wait = WebDriverWait(browser, 20) 
      browser.implicitly_wait(30) 
      browser.get('http://localhost:5000') 
      user = row[0] 
      password = row[1] 
      browser.xpath('html/body/div[1]/div/div/div[2]/form/div[2]/div/button').click() 
      browser.xpath(".//*[@id='Email']").send_keys(user) 
      browser.xpath(".//*[@id='next']").click() 
      browser.xpath(".//*[@id='Passwd']").send_keys(password) 

作業を。私はこれがこのように書くのは正しいとは思わない。

+0

あなたが上記を試してみると、現在シークレットを開いていないと言っていますか? – Josh

+0

コードが新しい反復を開始すると、新しいシークレットウィンドウが必要になります。 – andrew

+0

OK、現在何が起こっていますか? – Josh

答えて

0

一般的に使用されているブラウザでこのコードを試すことができます。お役に立てれば。

  • クローム:

    DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
    ChromeOptions options = new ChromeOptions(); 
    options.addArguments("incognito"); 
    capabilities.setCapability(ChromeOptions.CAPABILITY, options); 
    
  • FireFoxの:

    FirefoxProfile firefoxProfile = new FirefoxProfile();  
    firefoxProfile.setPreference("browser.privatebrowsing.autostart", true); 
    
  • のInternet Explorer:

    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); 
    capabilities.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true); 
    capabilities.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private"); 
    
  • オペラ:

    DesiredCapabilities capabilities = DesiredCapabilities.operaBlink(); 
    OperaOptions options = new OperaOptions(); 
    options.addArguments("private"); 
    capabilities.setCapability(OperaOptions.CAPABILITY, options); 
    
関連する問題