在做查询封装的时候,运行代码,浏览器启动了三次,页面对象层出现无法启动
在做查询封装的时候,运行代码,浏览器启动了三次,页面对象层出现selenium.common.exceptions.WebDriverException: Message: chrome not reachablebase层的代码
import unittest
from time import sleep
from selenium import webdriver
from pywinauto import Desktop
from pywinauto.keyboard import send_keys
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as Ec
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.select import Select
class BasePage:
definit(self):
global browser# 声明浏览器对象化
self.browser = webdriver.Chrome()# 设置等待时间
browser = self.browser# 加载网页
self.browser.get('http://127.0.0.1/index.php/Admin/Admin/login')#定位元素的关键字
def locator_element(self,loc=(By.NAME, 'username')):
return self.browser.find_element(*loc)#设置值的关键字
def send_keys(self,loc,value):
self.locator_element(loc).send_keys(value)#单击的关键字
def click_up(self,loc):
self.locator_element(loc).click()#点击商城
def click_shop(self,loc):
self.locator_element(loc).click()
def exit_to_frame(self):
self.browser.switch_to.default_content()
def go_to_frame(self,frame_name):#进入框架
browser.switch_to.frame(frame_name)#封装下拉框关键字
def encapsulation_choice(self,loc,value):
sel = Select(self.locator_element(loc))
sel.select_by_index(value)
def look_up(self,loc):
self.locator_element(loc).click()#获取文本值
页面对象层
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from 练习.base.base_page import BasePage
from 练习.pageproject.login_page import LoginPage
class ProductManage_page(BasePage):#页面元素
product_list_loc = (By.LINK_TEXT,'商城')
cat_id_loc = (By.NAME, 'cat_id')
botton_loc = (By.CLASS_NAME, 'btn')#页面动作 登录
def select_product(self):
sign_in = LoginPage()
sign_in.login_ecshop()# 点击商城
self.click_shop(ProductManage_page.product_list_loc)# 退出框架
self.exit_to_frame()# 进入框架
self.go_to_frame('workspace')
# 选取下拉框元素
self.encapsulation_choice(ProductManage_page.cat_id_loc,'7')
# 点击查询
self.look_up(ProductManage_page.botton_loc)
PM=ProductManage_page()
PM.select_product()
权限问题? 这个不清楚了。 管理员权限试试呢 是不是乱了 是不是乱了
页:
[1]