CSS明显比XPATH更性感!CSS再学一点儿

本文讨论了在Selenium中,前端开发者通常使用CSS选择器而非XPATH来定位元素,因为CSS更直观且避免了因多人协作可能导致的ID冲突问题。作者强调了浏览器不会警告重复ID的使用,开发者应在遇到此类场景时进行提示。
摘要由CSDN通过智能技术生成

在selenium应用,CSS比XPATH更性感

在这里插入图片描述
To style an element, Front end developers need to locate the element first and then apply styling rules. It looks like this:

#logo{ color: white; background: black; }

That CSS snippet says, apply color and background styles to any element with an ID of logo. Normally, ID will be unique in any HTML document carefully crafted. But there are chances for multiple developers working on the same page to use the same ID for different elements. Most of the time, without knowing it is already being used. Don’t worry, they’ll eventually catch up with that bug, but the point is the browser throws no warning. You should tell the developers when you find such scenarios.

The JavaScript developer who wants to take the logo for a spin writes code like this:

let element=document.querySelector(“#logo”); rotate(element);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值