- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试从以下元素中获取“样式”属性:
<td rowspan="31" style="background-color:Transparent;min-width: 19.14mm;WIDTH:21.26mm;" class="Ac165936899664594908cfec8fa25b2a0270c" height="548"><div style="word-wrap:break-word;white-space:pre-wrap;" class="Ac165936899664594908cfec8fa25b2a0270"> XXXXX </div></td>
但是当我使用下面的命令时:
driver.find_element_by_xpath("//a[@tabindex='"+str(m)+"']/../../following-sibling::td[2]").get_attribute('style')
Selenium 给我:
'背景颜色:透明;最小宽度:19.14mm;宽度:21.26mm;'
代替
'背景颜色:透明;最小宽度:19.14mm;宽度:21.26mm;'
最佳答案
style
属性是一个特殊属性,因为它的内容必须符合 HTML 文档规范和 CSS 文档规范。 HTML doc specs样式标签是这样说的:
The value of the style attribute must match the syntax of the contents of a CSS declaration block (excluding the delimiting braces)
在您阅读 CSS doc specs 之前,这不是很有帮助, 哪个州:
All CSS syntax is case-insensitive within the ASCII range (i.e., [a-z] and [A-Z] are equivalent), except for parts that are not under the control of CSS. For example, the case-sensitivity of values of the HTML attributes "id" and "class", of font names, and of URIs lies outside the scope of this specification. Note in particular that element names are case-insensitive in HTML, but case-sensitive in XML.
知道了这一点,我们可以得出结论,就 CSS 规范而言,width
=WIDTH
。问题仍然是为什么 selenium 将属性小写。好吧,事实证明获取元素的 CSS 是 special case getAttribute
。使用常规的 getAttribute
不会真正检查任何内容,并返回原始字符串值。然而,对于 CSS 的特殊情况,有一个额外的步骤来获取计算值,而不是原始值。这是确切的措辞:
- Let computed value be the result of the first matching condition: current browsing context’s document type is not "xml" computed value of parameter property name from element’s style declarations. property name is obtained from url variables. Otherwise "" (empty string)
所以你可以看到 style 属性实际上并不是直接来自原始文本值,而是来自计算值,这可能是小写的一切,只是因为这无关紧要,而且因为 CSS 属性通常是小写。这也很明显,因为在返回的文本中也插入了空格(提示它正在被解析和重新输出)。最后,如果您在样式标签中放置了无效的 CSS 属性,getAttribute
根本不会在字符串中返回它!
如果你需要原样的值,我通过最近的实验了解到 getAttribute
的 javascript 版本不会修改字符串文本,所以我建议使用驱动程序的 execute_script
获取方法。
关于python - 为什么 Selenium 给我一个不区分大小写的 Style 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59324068/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求提供代码的问题必须表现出对所解决问题的最低限度理解。包括尝试过的解决方案、为什么它们不起作用,以及预
出于某种原因,右栏中的精选文章忽略了“#elementtext”和“#elementtext:hover”属性。仅显示“p.element”和“img.element”。 有什么想法吗? 谢谢 - 塔
我有两个值,每个值都来自不同的枚举。我想检查这两者的允许组合,如果没有找到则执行默认操作。我能以某种方式对这两个值进行切换/大小写吗?我想避免使用多个 if/else 语句或遵循位掩码模式的枚举,只是
我需要 where 但 not 大小写。例如,我想找到没有名字“莎士比亚”的戏剧: _.where(listOfPlays, {author: !"Shakespeare", year: 1611})
我想实现一个 parking 场应用所以有一个带5个或更多 parking 位的车库当司机 parking 时,车库中的下一个空闲位置应该分配给他。 所以我有一个带 5 个或更多插槽的 table 上
我想使用 Erlang 来确定传递给函数的变量是否可以被数字整除。我考虑过使用 case 来执行此操作,但是我找不到解决方案。 case 是适合这项工作的工具吗? 示例:将数字传递给函数 f()。如果
我在 phpmyadmin 中创建了一个表,其列名如 first_name、last_name。当我使用命令显示表中的列名时,它会将它们显示为 first_name。 我想显示我的列名称,如 Firs
使用 Swift 4,如何使用这些规则格式化字符串: 如果单词超过 3 个字母,则首字母大写,否则大写 包含像 St-Michel 这样的连字符的 Pascal 大小写单词 我这里有初稿,但我一直在思
这个问题在这里已经有了答案: Why can't the switch statement be applied to strings? (23 个回答) 关闭 8 年前。 大家好 所以我正在尝试对
在 MVC 操作中,我如何访问使用多个同名值提交的“表单数据”中的值? 我做了什么:int、decimal、string 类型的值工作完美。 问题:每个变体都有一个复选框,所以当我尝试获取它时,它只显
while(1) { char buff[1000]; printf("Enter the word: "); fgets(buff, 1000
我有一个 Dllmain,它在线程附加到此 DLL 时分配线程本地存储。代码如下: BOOL APIENTRY DllMain(HMODULE hModule,
我有一个变量名,比如“WARD_VS_VITAL_SIGNS”,我想将它转换为 Pascal 大小写格式:“WardVsVitalSigns” WARD_VS_VITAL_SIGNS -> WardV
我是 Swift 编码的新手,正在尝试弄清楚如何在触摸节点时制作具有开/关功能的循环音频。我认为实现它的最佳方式是通过 SKAudioNode,但我不确定我在以下代码中做错了什么。当在节点上按下时 -
这是我第一次使用这种枚举,具有关联值类型的枚举,我需要根据对象的类型制作一个 switch 语句,我无法做到,这是枚举: enum TypeEnum { case foo(FooClass)
我想从字符串中删除所有下划线,下划线后面的字符为大写。因此,例如:_my_string_ 变为:MyString 同样:my_string 变为 MyString 有没有更简单的方法呢?我目前有以下内
如何在 Java 中将蛇形大小写转换为 Camel 形大小写? 输入:“input_in_snake_case” 输出:“InputInSnakeCase” 最佳答案 Guava通过其CaseForm
我们有一个表auth_group_access,那么如何使用呢? 在使用M方法时,对于带下划线的表名,可以采用如下方法。 M('AuthGroupAccess'); 对应sql语句SQL: S
我正在制作一个 pygame 游戏,每当我运行我的代码时,我都会收到错误 expected ':'。我知道在 match/case block 中使用 [ 和 ] 用于其他用途,但我该如何解决这个问题
有人能告诉我是否可以使用正则表达式将 url 转换为小写? 这是在 html img 标签内,所以我们可以通过标签找到网址。 这是我所拥有的一个例子 我需要在最后小写图像名称。 该文档包含更多 H
我是一名优秀的程序员,十分优秀!