python+seleniu+page object使用

记录在使用selenium webdriver实现UI自动化的一些


鼠标hover到某个字符后,选择显示出来的菜单中的某个选项

    def keli_center_selector(self,selector=1):
        # 等待颗粒中心显示,显示后做mouse hover操作。visibility_of方法的操作对象是webElement,可以使用driver.find_element*的方法获取
        main_menu = WebDriverWait(self.driver, 10).until(EC.visibility_of(self.driver.find_element(*PageLocators.keli_center)))

#       visibility_of_element_located方法的操作对象是Locator,也就是元素的地址
#        main_menu = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.XPATH,'//*[@id="bs-example-navbar-collapse-1"]/ul[1]/li[2]/a')))    

        ActionChains(self.driver).move_to_element(main_menu).perform()
        
        # wait for Fastrack menu item to appear, then click it
        fastrack = WebDriverWait(self.driver, 10).until(EC.visibility_of(self.driver.find_element(*PageLocators.bill_element)))
#        fastrack = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.XPATH,'//*[@id="bs-example-navbar-collapse-1"]/ul[1]/li[2]/div/div/div[4]/a')))
        fastrack.click() 

这种方法第一步使用action chain 的perform方法(perform执行的是前面move to element的操作),然后再对菜单中的元素进行点击操作


下拉菜单的选择,这里操作的下拉菜单不是以select为标签的

    def bill_element_create_dropdown_select_codeCollection(self):
        # 点击下单菜单
        self.driver.find_element(*PageLocators.bill_ele_create_dropdown).click()
        # 等待直到“50 代码类”显示出来
        WebDriverWait(self.driver, 10).until(lambda the_driver: the_driver.find_element(*PageLocators.bill_ele_create_dropdown_code_collection).is_displayed())
        
        menu2 = self.driver.find_element(*PageLocators.bill_ele_create_dropdown).find_element(*PageLocators.bill_ele_create_dropdown_code_collection)        
        #鼠标定位到子元素上
        webdriver.ActionChains(self.driver).move_to_element(menu2).perform()  
        #点击
        menu2.click()


使用webdriver.ActionChains(self.driver).move_to_element(menu2).click().perform()应该是一样的效果 ,着这种写法没有实际测试过。待验证。

-----------------------------------------------------

这两种实现方式有些相同,都是使用actionchain类。当调用ActionChains的方法时,不会立即执行,而是会将所有的操作按顺序存放在一个队列里,当你调用perform()方法时,队列中的时间会依次执行。


附注actionchain相关文章:http://www.jb51.net/article/92682.htm

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值