Suy*_*yog 2 selenium selenium-webdriver
我在下面的HTML路径下尝试捕获“收件箱”值,但无法使用Selenium Webdriver在google chrome中找到特定元素。
HTML路径:
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: white; text-align: left; width: 84px; height: 14px; padding-left: 1px; padding-top: 1px; left: 1px; top: 1px; background-color: rgb(102, 0, 153);">Inbox"
<img src="/images/tridown.gif" style="position: absolute; width: 8px; height: 4px; top: 9px; left: 75px;">
</div>"Inbox"
<img src="/images/tridown.gif" style="position: absolute; width: 8px; height: 4px; top: 9px; left: 75px;">
</div>
Run Code Online (Sandbox Code Playgroud)
我认为left和top是Inbox下拉菜单的唯一标识符,因此您能否帮助我们编写命令以从HTML上方获取“ Inbox”值
正如Michas和Saritha G所建议的那样,您的HTML代码的格式正确,但是话虽如此。请在下面使用此示例:
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: white; text-align: left; width: 84px; height: 14px; padding-left: 1px; padding-top: 1px; left: 1px; top: 1px; background-color: rgb(102, 0, 153);"></div>
Run Code Online (Sandbox Code Playgroud)
如果要为上述元素检索“样式”属性的值,则需要首先找到该元素:
firefox = webdriver.Firefox()
element = firefox.find_element_by_css_selector("this element css selector here")
attributeValue = element.get_attribute("style")
Run Code Online (Sandbox Code Playgroud)
然后attributeValue应该具有以下字符串“ 位置:绝对;可见性:继承;溢出:隐藏;光标:默认值;颜色:白色; text-align:左;宽度:84px;高度:14px; padding-left:1px; padding- top:1px; left:1px; top:1px; background-color:rgb(102,0,153) ;“
我以Python为例。
| 归档时间: |
|
| 查看次数: |
5355 次 |
| 最近记录: |