Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Using Webdriver Selenium to get the value of “style” element

I have below HTML path for which I am trying to capture "Inbox" value but I am not able to find particular element in google chrome using Selenium Webdriver.

HTML Path :

<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>

I think left and top is unique identifer for Inbox dropdown, so can you please help us to write command to get "Inbox" value from above HTML

like image 630
Suyog Avatar asked Oct 25 '25 06:10

Suyog


1 Answers

As Michas and Saritha G suggested, your HTML code is formatted correctly, but having said that. Please use this example below:

<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>

If you want to retrieve the value for "style" attribute for the element above, you need to first locate this element:

firefox = webdriver.Firefox()
element = firefox.find_element_by_css_selector("this element css selector here")
attributeValue = element.get_attribute("style")

Then attributeValue should have this following string "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);"

I am using Python as an example.

like image 114
Yu Zhang Avatar answered Oct 27 '25 04:10

Yu Zhang