python之处理selenium中的获取元素属性问题 || 处理selenium中的获取文本问题 || 处理selenium中的窗口切换问题 || 处理selenium中的鼠标悬停问题
处理selenium中的获取元素属性问题
①获取‘我的订单’元素class属性值:
at = self.driver.find_element_by_link_text('我的订单').get_attribute('class')
②判断‘我的订单’元素的classs属性值是否为active:
self.assertEqual(at,u'active')
处理selenium中的获取文本问题
获取文本
button_name = self.driver.find_element_by_id("sign_in_display").text
处理selenium中的窗口切换问题
①获取当前页面的句柄
ch = driver.current_window_handle
②获取当前浏览器打开的页面所有句柄
ah = driver.window_handles
③切换句柄
driver.switch_to.window(ah[1])
处理selenium中的鼠标悬停问题
①导入selenium中的Actionchains类
from selenium.webdriver.common.action_chains import ActionChains
②识别需要悬停的元素
ele = self.driver.find_element_by_class_name('member-top')
③鼠标移到悬停元素上
ActionChains(self.driver).move_to_element(ele).perform()