如何使用Selenium Web驱动程序设置元素的新样式 [英] How can i set new style of element using selenium web-driver
本文介绍了如何使用Selenium Web驱动程序设置元素的新样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用(selenium webdriver-java)为包含打开小颜色选择窗口的按钮的页面构建测试计划.
I am building test plan using (selenium webdriver - java) for page that contain button which open small color selection window.
这是颜色选择窗口右侧面板的代码:
this is the code of the right panel of the color selection window:
<span class="ui-colorpicker-bar-layer-pointer">
<span class="ui-colorpicker-bar-pointer" style="top: 51.0333px;"></span>
问题是我该如何设置新样式.....,我找到了此解决方案:
the question is how can i set new style..... , i found this solution:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('colorPickIcon').setAttribute('style', '22.3333px')");
它不起作用....任何建议吗?
and it doesn't work....any advice's?
推荐答案
您可以使用findElement代替getElementById
You can use findElement instead of getElementById,
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement element = driver.findElement(By.id("colorPickIcon"));
js.executeScript("arguments[0].setAttribute('style', 'top:22.3333px')", element);
您可以参考链接如何在Selenium中使用JavaScript WebDriver Java
这篇关于如何使用Selenium Web驱动程序设置元素的新样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文