1

I'm new to Selenium's webdriver and Python. I know about this article about getting the HTML source, but I don't want the entire HTML line for a DOM object, just the content in between the tags. I also looked at webdriver source code for help on finding this button DOM object

for example:

<button id = "picview">Pic View</button>

How do I just get "Pic View"?

Also, using get_attribute("button id"), How would I get this specific button id as there are multiple buttons on the page with button id?

For example:

picbox_elem_attr = picbox_elem.get_attribute('button id')
print picbox_elem_attr

How do I ensure that picbox_elem_attr variable is set to the "picview" button and not some other button?

I don't have a

driver.find_element_by_name("xxx")

or a

driver.find_element_by_id("aaa")

to use to find this button.

Community
  • 1
  • 1
StacyM
  • 1,036
  • 5
  • 23
  • 41

2 Answers2

2

To get text of an element use the text property. For example:

text_inside_button_id = driver.find_element_by_id("picview").text

Here is some additional documentation to help you with the webdriver binding library. http://goldb.org/sst/selenium2_api_docs/html/

Cola
  • 2,097
  • 4
  • 24
  • 30
  • Thanks, I've looked through the api doc, but don't know where to find this type of functionality. I know the high level find functions from looking at the source code, but your doc might be easier if I knew where to look. – StacyM Oct 10 '13 at 22:44
  • Look under selenium.webdriver.remote.webelement: WebElement implementation. – Cola Oct 10 '13 at 22:59
0

I forgot about xpath. Oops!

driver.find_element_by_xpath('//*[@id="picview"]')

and then you can right-click the object and use xpath within the dev tools.

StacyM
  • 1,036
  • 5
  • 23
  • 41