content I want to ...">

Get text from all elements matching the pattern in selenium

I have a website with form elements:

<td id="subject_23432423">content I want to read</td>

How to use Selenium RC (with Python binding specifically) to read content from all of these elements? I went through all the commands, and although there are many options for finding a single item, none of the teams processes lists from multiple matches. For example, I can find the contents of a specific element using:

content = sel.get_text("td[@id='subject_23432423']")

but this assumes that I already know the identifier, which I do not do, because it is generated dynamically.

+3
source share
4 answers

API Selenium 1, JavaScript, XPath //td[contains(@id, "subject_")], subject_ . , Selenium browserbot XPath IE, , . Firefox :

var tds = document.evaluate("//td[contains(@id, \"subject_\")]", document, null,
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 
for ( var i = 0; i < tds.snapshotLength; i++) {
   var td = tds.snapshotItem(i);
   // get text using td.textContent and add it to array or whatever...
   // and return it
}

return ...

script selenium.getEval

, Selenium 2 (WebDriver), API. findElementsBy, XPath //td[contains(@id, "subject_")],

+3

count = sel.get_xpath_count("xpath=//td[starts-with(@id,'subject_')]")
someArray = []
for i in count:
  someArray[i] = sel.get_text("xpath=//td[starts-with(@id,'subject_')][" + i + "]")

BeautifulSoup lxml

html = sel.get_html_source()
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(html)
#use beautifulsoup to do what you want
+5

, , Selenium, TestPlan ( Selenium HTMLUnit ). TestPlan script .

for %Element% in (response //td[starts-with(@id,'subject_')])
  Notice %Element%
end

, .

+1

2

= driver.findElements(By.xpath( "//td [ (@id, 'subject_')]" )) int size = subjects.size();

0

Source: https://habr.com/ru/post/1769775/


All Articles