首页 > 解决方案 > 在 Python 中返回上一个浏览器窗口

问题描述

我正在用 Python selenium 编写脚本并尝试返回到以前的浏览器窗口。当代码运行时,它会点击 print_print 并转到不同 url 链接中的打印设置页面。我正在尝试关闭它打开的打印设置窗口并转到上一个窗口。

#!/usr/bin/env python
# coding: utf-8




from selenium import webdriver                             # Import module
from webdriver_manager.chrome import ChromeDriverManager   # import chromedrivermanager

from bs4 import BeautifulSoup

from selenium.webdriver.common.keys import Keys
import csv 


 from time import sleep


 driver = webdriver.Chrome(ChromeDriverManager().install())  
 sleep(2)
 import pandas as pd
 data=pd.read_csv("C:/Selenium/boltsemployees.csv")

 # Login
 for i in range(0,data.shape[0]):
driver.get("https://test.first.bank/bolts/launchpad/")


 First=data['First'][i]
 Last=data['Last'][i]
 Email=data['Email'][i]
 sleep(2)
 user_id=driver.find_element_by_xpath("/html/body/div/div/ui-view/logicontent/form/div/md-input-container")
 sleep(2)
 user_id.send_keys("login")
 password=driver.find_element_by_xpath("/html/body/div/div/ui-viecontent/form/div/md-input-container[2]/input")
 password.send_keys("password")
 login_btn=driver.find_element_by_xpath("/html/body/div/div/ui-view/login/dcontent/form/button").click()


 initial_package_submit=driver.find_element_by_xpath("/html/body/div[3]/md-dialog/div/md-tabs/md-tabs-content-wrapper/md-tab-content[2]/div/blt-tab/div/ng-transclude/ng-include/div/blt-tab-content/div/div/div/div[2]/ng-transclude/div/div[2]/div[2]/blt-button[2]/button")
 initial_package_submit.click()
 sleep(2)
 esign=driver.find_element_by_xpath("/html/body/div[3]/md-dialog/div/md-tabs/md-tabs-content-wrapper/md-tab-content[2]/div/blt-tab/div/ng-transclude/ng-include/div/blt-tab-content/div/div/div/div[2]/ng-transclude/div/div[1]/md-list/md-list-item[2]/div/button").click()
 sleep(2)
 esign_decline=driver.find_element_by_xpath("/html/body/div[3]/md-dialog/div/md-tabs/md-tabs-content-wrapper/md-tab-content[2]/div/blt-tab/div/ng-transclude/ng-include/div/blt-tab-content/div/div/div/div[2]/ng-transclude/div/div[2]/div[1]/blt-button/button/div[1]")
 esign_decline.click()
 sleep(2)
 print_btn=driver.find_element_by_xpath("/html/body/div[3]/md-dialog/div/md-tabs/md-tabs-content-wrapper/md-tab-content[2]/div/blt-tab/div/ng-transclude/ng-include/div/blt-tab-content/div/div/div/div[2]/ng-transclude/div/div[2]/blt-button[1]/button")
 print_btn.click()
 sleep(2)
 print_print=driver.find_element_by_xpath("/html/body/div[3]/div[3]/md-dialog/md-dialog-actions/button[2]")
 print_print.click()
 sleep(2)

标签: pythonpython-3.xseleniumanaconda

解决方案


推荐阅读