java Selenium,定位 伪元素.UI自动化

Java中,要获取这个表单字段前面的必填标识星号"*",因为是用的伪元素,无法直接通过常规定位获取字符,需要用到 JavascriptExecutor。

java 复制代码
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public static void queryInfo(WebDriver driver){
    // 目标元素的xpath路径
    String time="//*[@id=\"rc-tabs-0-panel-1\"]/div[2]/div/div/form/div[1]/div/div[1]/label";
    // 获取元素
    WebElement element =driver.findElement(By.xpath(time));
    // 获取伪元素
    JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
    String display =  jsExecutor.executeScript("return window.getComputedStyle(arguments[0], ':before').getPropertyValue('content')",element).toString();
    System.out.println(display);
}

执行结果:

感谢大佬的案例:无法使用Selenium中的javascript执行器定位伪元素-腾讯云开发者社区-腾讯云

相关推荐
智慧地球(AI·Earth)4 分钟前
用AI重构Python开发:从API调用到本地部署,代码全流程自动化实战
python·自动化·api
旦莫2 小时前
测试工程师如何用AI生成测试用例?我的提示词模板分享
人工智能·python·测试开发·自动化·测试用例·ai测试
Chengbei113 小时前
红队专属Bing Dork自动化工具,敏感信息侦察效率拉满、自动生成可视化信息泄露审计报告
java·人工智能·安全·web安全·网络安全·自动化·系统安全
不一样的故事1265 小时前
禁止访问 是 SVN 标准 403 权限拒绝错误
运维·安全·自动化
微刻时光5 小时前
影刀RPA:循环相似元素列表深度解析与实战指南
java·人工智能·python·机器人·自动化·rpa·影刀
米高梅狮子6 小时前
03.Kubernetes自动化部署和namespace、pod
容器·kubernetes·自动化
Ulyanov6 小时前
《玩转QT Designer Studio:从设计到实战》 QT Designer Studio组件化开发与UI组件库构建
开发语言·python·qt·ui·雷达电子战系统仿真
AALoveTouch6 小时前
某麦网抢票:基于Wireshark协议分析
网络·测试工具·wireshark
私人珍藏库7 小时前
[Windows] 电子教鞭演示工具 PointerStick v7.11
windows·自动化·工具·软件·多功能
xiaohuoji1298 小时前
震荡行情下的自动化交易:从架构视角看高抛低吸工具选型
架构·自动化·区块链