Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.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/8/python-3.x/17.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 er.switch\u to.window(browser.window\u句柄[-1])_Python_Python 3.x_Selenium Webdriver_Selenium Chromedriver_Browser Automation - Fatal编程技术网

Python er.switch\u to.window(browser.window\u句柄[-1])

Python er.switch\u to.window(browser.window\u句柄[-1]),python,python-3.x,selenium-webdriver,selenium-chromedriver,browser-automation,Python,Python 3.x,Selenium Webdriver,Selenium Chromedriver,Browser Automation,现在代码看起来是这样的,它工作得很好: #/bin/usr/env python # =========================================================== #创作人:理查德·巴雷特 #组织:DVISD #部门:数据服务 #目的:向天空管理 #日期:2020年1月4日 # =========================================================== 进口硒 进口舒蒂尔 导入xlsxwriter 导入操作系统

现在代码看起来是这样的,它工作得很好:

#/bin/usr/env python
# ===========================================================
#创作人:理查德·巴雷特
#组织:DVISD
#部门:数据服务
#目的:向天空管理
#日期:2020年1月4日
# ===========================================================
进口硒
进口舒蒂尔
导入xlsxwriter
导入操作系统
导入单元测试
导入请求
导入子流程
导入getpass
导入平台
导入pynput
导入日志记录
导入时间
从pynput.keyboard导入键,控制器
从selenium导入webdriver
从selenium.webdriver.common.keys导入密钥
从selenium.webdriver.common.by导入
从selenium.webdriver.support将预期的_条件导入为EC
从selenium.webdriver.support.ui导入WebDriverWait
起始日期时间导入日期
decrypt=“gpg--output secrets.json--decrypt secrets.gpg”
如果os.path.exists(“secrets.gpg”):
返回的_值=subprocess.call(decrypt,shell=True)
其他:
打印(“文件不存在!”)
打印(“您可能应该创建一个秘密!”)
打印(“gpg—输出文件名.gpg—加密文件名.json”)
导入json
以open('secrets.json','r')作为f:
config=json.load(f)
#定义
#按名称查找元素
#通过xpath查找元素
#通过链接文本查找元素
#通过部分链接文本查找元素
#按标签名称查找元素
#按类名称查找元素
#通过\u css\u选择器查找\u元素\u
#系统变量
今天=日期。今天()
日期=今天.strftime(“%m/%d/%Y”)
node=platform.node()
system=platform.system()
username=getpass.getuser()
version=platform.version()
键盘=控制器()
#上载路径变量
文件\u input\u inactive\u users=os.path.abspath(“C:\Imports\customNameneedsformating\u 02\u 24\u 2020\u 20\u 14\u 12\u richardbarrett”)
#URL变量
登录\u url=“”
重定向\u url=“”
报告\u调度程序\u url=“”
自定义_报告_url=“”
#检查Chrome的版本
#系统的WebDriver路径
如果platform.system()==('Windows'):
browser=webdriver.Chrome(“C:\ProgramFiles(x86)\Google\Chrome\chromedriver.exe”)
elif platform.system()==('Linux'):
browser=webdriver.Chrome(可执行文件路径='/home/rbarrett/Drivers/Google/Chrome/chromedriver\u linux64/chromedriver')
elif platform.system()==('Darwin'):
browser=webdriver.Chrome(可执行文件路径=“~/Drivers/Google/Chrome/chromedriver\u mac64/chromedriver”)
其他:
打印(“您确定已将Selenium Webdriver安装在正确的路径中吗?”)
#拆卸法
def拆卸(自):
self.browser.close()
#关机方法
def关闭(自):
self.browser.quit()
#父URL
browser.get(“https://skyward-student.del-valle.k12.tx.us/scripts/wsisa.dll/WService=wsEAplus/seplog01.w?nopopup=true")
时间。睡眠(5)
#凭证需要单元测试
用户名=浏览器。通过id(“登录”)查找元素
密码=浏览器。通过id(“密码”)查找元素
用户名。发送密钥(配置['user']['name'])
密码。发送密钥(配置['user']['password'])
#身份验证提交。单击()
#对于XPATH=/*[@id='bLogin']
element=WebDriverWait(浏览器,20)。直到(
EC.element可点击((By.XPATH,“/*[@id='bLogin']))
元素。单击();
打印(“登录!”)
打印(“认证”)
#单击并跨越Skyward联系人访问
#管理XPATH=/*[@id='nav\u ContactAccess']/span
element=WebDriverWait(浏览器,20)。直到(
EC.element可点击((By.XPATH,“/*[@id='nav\u ContactAccess']/span”))
元素。单击();
#单击安全用户
#XPATH=//a[@id='nav_SecuredUsers']/span
element=WebDriverWait(浏览器,20)。直到(
EC.element可点击((By.XPATH,//a[@id='nav\u SecuredUsers']/span”))
元素。单击();
#加载users.json文件
将open('users.json','r')作为f:
config=json.load(f)
#发送密钥进行查找
#XPATH=/*[@id='brSecuredUserLookupInput']
target_user=WebDriverWait(浏览器,20)。直到(
EC.element可点击((By.XPATH,“/*[@id='brsecureduserlookupinput']))
目标用户。发送密钥(配置['sec\u group\u remove']['name\u key']);
目标用户。发送密钥(密钥。返回);
#需要删除Sec组的元素上的展开按钮
#“bd_打开”类
element=WebDriverWait(浏览器,20)。直到(
EC.元素可点击((按.CLASS\u名称,“bd\u关闭”))
元素。单击()
#单击“按链接文本删除所有组”
#通过链接文本查找元素
element=WebDriverWait(浏览器,20)。直到(
EC.element可点击((By.LINK文本,“删除所有组”))
元素。单击()
#单击“按ID确定”
#XPATH/*[@id='msgBtn1']
element=WebDriverWait(浏览器,20)。直到(
EC.element可点击((By.XPATH,“/*[@id='msgBtn1']”)
元素。单击()

解决这些问题的最简单方法是使用。在那里,您可以手动浏览应用程序的各个步骤,保存应用程序,运行应用程序以确保其正常运行。这一切都是通过简单地与您的Web应用程序交互(如录制宏)。它的美妙之处在于,它为您生成代码,并识别定位要交互的对象(或定位要断言以进行自动测试的信息)所需的CSS/HTML选择器

<a class="button" id="msgBtn1" tabindex="5" href="javascript:if (cbs('msgBtn1')) {closeMessage(false); validateForm('xAllGroups','ssusrhttp001.w','ssusrbrws001.w'); cancelEvent();}" role="button" style="width: 100px; font-weight: normal;">OK&nbsp;</a>