Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium xpath all(//*)不';我不能接受所有css元素_Python_Selenium_Xpath - Fatal编程技术网

Python Selenium xpath all(//*)不';我不能接受所有css元素

Python Selenium xpath all(//*)不';我不能接受所有css元素,python,selenium,xpath,Python,Selenium,Xpath,我正在尝试使用selenium(XPath)列出不同网站上的每种颜色,但我不知道为什么我的脚本没有得到所有颜色 background_ele = browser.find_elements_by_xpath("//*[contains(@style,'background')]") colors_ele = browser.find_elements_by_xpath("//*[contains(@style,'color')]") background_colors = [x.value_of

我正在尝试使用selenium(XPath)列出不同网站上的每种颜色,但我不知道为什么我的脚本没有得到所有颜色

background_ele = browser.find_elements_by_xpath("//*[contains(@style,'background')]")
colors_ele = browser.find_elements_by_xpath("//*[contains(@style,'color')]")
background_colors = [x.value_of_css_property('background-color') for x in background_ele]
colors = [x.value_of_css_property('background-color') for x in colors_ele]
这段代码应该获取每个具有背景或颜色属性的元素,但当我为此网站运行它时:“www.example.com”我看不到下面显示在页脚和页眉上的颜色:

background-color: rgb(54, 64, 66) !important;
我只打印那些:

['rgba(255, 255, 255, 0)', 'rgba(0, 0, 0, 0)', 'rgba(169, 68, 66, 1)', 'rgba(0, 0, 0, 0)']
我的代码是否有问题,或者使用selenium是否有更有效的方法

更新

我的脚本实际上只接受html中的标记,而不接受css文件中的标记

<div class="example"style="src="https://example.com/img/slider.jpg"></div>

Selenium不处理DOM结构中缺少的CSS属性。或者,您可以通过为每个需要的节点应用类来使用允许以标准方式查找元素的内容: 下面的例子是
//div[contains(@class,'found')]

$(文档).ready(函数(){
$(“*”).filter(函数(){
return$(this.css(“背景色”)=“rgb(54,64,66)”;
}).text(“真”).addClass(“找到”);
});
.white{
背景色:rgb(255、255、255);
}
布莱克先生{
背景色:rgba(0,0,0,0);
}
.胭脂红{
背景色:rgba(169,68,66,1);
}
.宇宙{
背景色:rgb(54,64,66);
}
.发现{
颜色:绿色!重要;
字体大小:粗体;
}

假的
假的
假的

false
看起来有些
样式是在单独的样式文本/css块中定义的。试着去拿那些并寻找
backgroundColor
s.@wp78de我怎样才能找到那些含硒的呢?它不应该自动捕捉它们吗?@jjyoh你想得到所有有效的计算颜色吗?