是否可以在selenium中设置元素的背景颜色 [英] Is it possible to set a background color of an element in selenium

查看:591
本文介绍了是否可以在selenium中设置元素的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium和Java,我想在屏幕上更改元素的背景颜色。
有可能吗?

I am using Selenium with Java, and I want to change a background color of an element on the screen. Is it possible?

推荐答案

您可以使用执行脚本使用javascript进行设置

You can set it using javascript by using executescript

((JavascriptExecutor) driver).executeScript("document.getElementById('locatorid').style.backgroundColor = 'lightblue';");

如果需要按类名或名称找到它,有几个javascript函数

There are several javascript functions if you need to locate it by classname or name

document.getElementsByName
document.getElementsByClassName

希望这可以帮助你....如果你需要更准确的答案...请发布元素html源

Hope this helps you....if u need more accurate answer...pls post the element html source

这篇关于是否可以在selenium中设置元素的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆