I am writing a small visual parser through selenium in Python. My program enters the site, authorizes, reads the block I need, analyzes, goes further. It happens like this

while i<25: s1 = '(//span[@class="wo-subject"])[' s2 = ']' i = str(i) s = s1+i+s2 name = driver.find_element_by_xpath(s).text ... i = int(i) i = i+1 

Such blocks are not really 25, but how to first find out how many elements in my xpath condition I didn’t guess and I can’t find. Therefore, I ask for your help. How can I find out how many elements per page fit my condition?

    1 answer 1

    There are various strategies to locate elements in a page. You can use the most appropriate one for your case. Selenium provides the following methods to locate elements in a page:

     find_element_by_id find_element_by_name find_element_by_xpath find_element_by_link_text find_element_by_partial_link_text find_element_by_tag_name find_element_by_class_name find_element_by_css_selector 

    To find multiple elements (these methods will return a list):

     find_elements_by_name find_elements_by_xpath find_elements_by_link_text find_elements_by_partial_link_text find_elements_by_tag_name find_elements_by_class_name find_elements_by_css_selector 

    http://selenium-python.readthedocs.io/locating-elements.html

    • Yes, it helped me, thanks! - Alexander
    • one
      Russian Glassflow Flow - answers should be given in Russian - Andrew Bystrov