selenium 之 css定位

selenium css定位

css概述:

  1. css(cascading style sheets)是一种语言,它用来描述HTML和XML的元素显示样式。

  2. css语言中有css选择器,在selenium中也可以使用这种选择器来进行元素定位。

  3. css定位方式比xpath快,而且css的语法也非常强大。

    定位方法:find_element_by_css_selector()

    css定位方式:1. id选择器 2. class选择器 3. 元素选择器 4. 属性选择器 5. 层级选择器

  4. id选择器

    根据元素id属性来选择

    格式:#id属性值 如:#userA(选择id属性值为userA的所有元素)

    find_element_by_css_selector('#userA').send_keys('hello selenium')

  5. class选择器

    根据元素class属性来选择

    格式:.class属性值 如:.telA(选择class属性值为telA的所有元素)

    find_element_by_css_selector('.telA').send_keys('hello selenium')

  6. 元素选择器

    根据元素标签名来选择

    格式:element 如: input(选择所有input元素)

    find_element_by_css_selector('input').send_keys('hello selenium')

  7. 属性选择器

    根据元素的属性名和值来选择

    格式:attribute=value 如:type='password' (选择所有type属性为password的值)

    find_element_by_css_selector('type="password"').send_keys('hello selenium')

  8. 层级选择器

    根据元素的父子关系来选择

    格式:element>element 如:p>input(返还所有p元素下所有的input元素)

    find_element_by_css_selector('p>input').send_keys('hello selenium')

相关推荐
乌暮1 小时前
拆解网页的底层逻辑:用费曼学习法讲透 HTML 与 CSS
前端·css·学习·html
传人once13 小时前
多图片上传预览功能如何写
前端·css·html·jquery·html5
传人once15 小时前
悬停旋转放大和位移效果如何写
javascript·css·动画
听风3471 天前
windplay网页创意实验场
css·html·创意·website·windplay
福兮说1 天前
设计稿是 #4A7C6F,页面量出来是 #4B7C6F:HEX、HSL、透明度、canvas 来回转的七个坑
前端·javascript·css·canvas
weixin_448290252 天前
书庐开发实战教学
javascript·css·html
传人2 天前
悬停旋转放大和位移效果如何写
前端·javascript·css
geovindu2 天前
css: Timeline scribble
前端·css·iphone
易朵朵3 天前
CSS 格式化上下文
css·vue.js
COOLMO研究AI3 天前
企业官网服务页的信息架构怎么设计:从用户问题到语义化 HTML
前端·css·html