[英]Selenium Webdriver with Python - obtaining the string or contents in between html tags
I'm new to Selenium's webdriver and Python. 我是Selenium的webdriver和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.
我了解有关获取HTML源代码的这篇文章 ,但是我不希望DOM对象的整个HTML行,而只是标签之间的内容。 I also looked at webdriver source code for help on finding this button DOM object
我还查看了webdriver源代码,以查找有关此按钮DOM对象的帮助。
for example: 例如:
<button id = "picview">Pic View</button>
How do I just get "Pic View"? 我如何获得“ 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? 另外,使用get_attribute(“ button id”),如何获得此特定的按钮id,因为页面上有多个具有按钮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? 如何确保将picbox_elem_attr变量设置为“ picview”按钮,而不是其他按钮?
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. 用于查找此按钮。
To get text of an element use the text property. 要获取元素的文本,请使用text属性。 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. 这是一些其他文档,可帮助您使用webdriver绑定库。 http://goldb.org/sst/selenium2_api_docs/html/
http://goldb.org/sst/selenium2_api_docs/html/
I forgot about xpath. 我忘记了xpath。 Oops!
哎呀!
driver.find_element_by_xpath('//*[@id="picview"]')
and then you can right-click the object and use xpath within the dev tools. 然后,您可以右键单击该对象,然后在开发工具中使用xpath。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.