How to get all forms on webpage using python selenium?
Question: I searched for answer before ask here but didn't get lucky enough. So here it
goes, I am doing web scraping using python selenium. before choosing selenium
I checked for mechanize, scrapy but I failed to execute some button clicks
with them then I checked selenium it seems okay with some cons. I am saying
all this because if I chose the wrong tool then please correct me before it is
too late.

My question about selenium is how do I get all elements on webpage using
xpath. eg: On webpage each webpage I got 10 forms and each of them has a
button. So I want to get all the forms on web page to loop on them and click
button one by one.

eg:

    
    
    <form id="#F0">
        <input type="button" name="itens" value="Items" class="texField2" onClick="somefunction()"/>
    </form>
    <form id="#F0">
        <input type="button" name="itens" value="Items" class="texField2" onClick="somefunction()"/>
    </form>
    <form id="#F1">
        <input type="button" name="itens" value="Items" class="texField2" onClick="somefunction()"/>
    </form>
    <form id="#F2">
        <input type="button" name="itens" value="Items" class="texField2" onClick="somefunction()"/>
    </form>
    <form id="#F3">
        <input type="button" name="itens" value="Items" class="texField2" onClick="somefunction()"/>
    </form>
    <form id="#F4">
        <input type="button" name="itens" value="Items" class="texField2" onClick="somefunction()"/>
    </form>
    

Another thing, What I am doing is I click on button on 1st form (it takes me
to another page, I go back to history and click on 2nd button then go back to
history and so on) it seems scraping would be slow. Is there any better way to
do the same?

Thank you !!

Edit:

    
    
    from selenium import webdriver
    mydriver = webdriver.Firefox()
    
    baseurl = """http://www.comprasnet.gov.br/consultalicitacoes/ConsLicitacao_Filtro.asp?numprp=&dt_publ_ini=24/02/2016&dt_publ_fim=10/03/2016&chkModalidade=1,2,3,20,5,99&chk_concor=31,32,41,42&chk_pregao=1,2,3,4&chk_rdc=1,2,3,4&optTpPesqMat=M&optTpPesqServ=S&chkTodos=-1&chk_concorTodos=-1&chk_pregaoTodos=-1&txtlstUf=&txtlstMunicipio=&txtlstUasg=&txtlstGrpMaterial=&txtlstClasMaterial=&txtlstMaterial=&txtlstGrpServico=&txtlstServico=&txtObjeto="""
    mydriver.get(baseurl)
    mydriver.find_element_by_id('ok').click()
    buttons  = mydriver.find_element_by_xpath("//form//input[@type='button']")
    for button in buttons:
        button.click() 
    


Answer: You can get forms buttons by xpath with code below:

    
    
    buttons = driver.find_elements_by_xpath(".//form//input[@type='button']")
    

And iterate them via simple for loop:

    
    
    for button in buttons:
        button.click() 
    

Alternativelly you can use [find_elements_by_css_selector](http://selenium-
python.readthedocs.org/locating-elements.html#locating-elements) function to
get elements:

    
    
    buttons = driver.find_elements_by_css_selector("input[type='button']")
    

