如何用Python在Selenium中高效获取元素属性及文本信息?
- 内容介绍
- 文章标签
- 相关推荐
本文共计224个文字,预计阅读时间需要1分钟。
处理Selenium中获取元素属性问题的代码如下,已简化并确保不超过100个字:
python获取我的订单元素的class属性值:at=self.driver.find_element_by_link_text('我的订单').get_attribute('class')判断我的订单元素的class属性值是否为ac:is_ac=at==ac
处理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类
②识别需要悬停的元素
ele = self.driver.find_element_by_class_name('member-top')③鼠标移到悬停元素上
ActionChains(self.driver).move_to_element(ele).perform() 去期待陌生,去拥抱惊喜。
本文共计224个文字,预计阅读时间需要1分钟。
处理Selenium中获取元素属性问题的代码如下,已简化并确保不超过100个字:
python获取我的订单元素的class属性值:at=self.driver.find_element_by_link_text('我的订单').get_attribute('class')判断我的订单元素的class属性值是否为ac:is_ac=at==ac
处理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类
②识别需要悬停的元素
ele = self.driver.find_element_by_class_name('member-top')③鼠标移到悬停元素上
ActionChains(self.driver).move_to_element(ele).perform() 去期待陌生,去拥抱惊喜。

