如何使用Selenium WebDrive获取`style ='background-image:url`? [英] how to fetch `style="background-image: url` using selenium webDrive?
本文介绍了如何使用Selenium WebDrive获取`style ='background-image:url`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Selenium webDrive抓取了这个元素:
I grabbed this element using selenium webDrive:
<div class="body" style="background-image: url('http://d1oiazdc2hzjcz.cloudfront.net/promotions/precious/2x/p_619_o_6042_precious_image_1419849753.png');">
如何获取值: http://d1oiazdc2hzjcz.cloudfront.net/promotions/precious/2x/p_619_o_6042_precious_image_1419849753.png
吗?
我不确定这是一个内部值,而不仅仅是"src"属性.
I'm not sure as this is an inner value, and not just an "src" attribute.
推荐答案
getCssValue();会帮助您
getCssValue(); will help you
WebElement img = driver.findElement(By.className('body'));
String imgpath = img.getCssValue("background-image");
然后您可以拆分不需要的字符串"url('"
then you can split the unwanted string "url('"
PS:删除问题中的javascript标记
PS : Remove the javascript tag in your question
这篇关于如何使用Selenium WebDrive获取`style ='background-image:url`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文