【发布时间】:2019-07-18 02:02:30
【问题描述】:
我正在使用 selenium webdriver 测试网站,但我在获取另一个属性的子属性的值时遇到了困难。对我来说,这个 2nd/child 级别总是返回为 null。
当尝试获取上层属性/属性的值时,它可以使用以下代码正常工作:
return Element1.GetAttribute("baseURI");
return Element2.GetAttribute("innerText");
上面的返回我期望的文本/字符串。但是,如果我尝试获取子属性的值,如下所示:
return Element3.GetAttribute("style.cssText");
return Element4.GetAttribute("style.fontWeight")
我得到空值。当我查看上面元素的 DOM/属性时,我确实看到了它们的值。
cssText: "font-weight: bold;"
fontWeight: "bold"
如果我在开发工具栏中右键单击属性并选择“复制属性路径”,我会得到以下信息:
style.cssText
style.fontWeight
所以我认为问题在于我如何通过假设我从开发人员工具栏中复制的内容是正确的来引用子属性。我已经尝试过除句点之外的其他分隔符,但我现在仍然很幸运。
我正在尝试找出返回值的语法 -
object.style.fontWeight
我试过了:
parent.child.GetCSSValue("css"), parent-child.GetCSSValue("css")
parent.child.GetAttribute("attrib"), parent-child.GetAttribute("attrib")
parent.child.GetProperty("prop"), parent-child.GetProperty("prop")
这些都以 null 或 empty.string 的形式返回
【问题讨论】:
-
这不是重复的(我不是要求所有值)并且共享的链接甚至没有得到批准的有利答案
-
我正在尝试找出返回存储在 - object.style.fontWeight 中的值的语法:parent.child.GetCSSValue("css"), parent-child.GetCSSValue(" css") parent.child.GetCSSValue("css"), parent-child.GetCSSValue("css") 或: parent.child.GetAttribute("attrib"), parent-child.GetAttribute("attrib") parent.child .GetAttribute("attrib"), parent-child.GetAttribute("attrib") 甚至:parent.child.GetProperty("prop"), parent-child.GetProperty("prop") parent.child.GetProperty("prop "), parent-child.GetProperty("prop") 这些都返回为 null 或 empty.string
标签: javascript c# selenium getcomputedstyle getpropertyvalue