I'm trying to learn selenium
with python
and have been trying to automate:
Search
of thenext button
on the page.Click
on this button.Save each HTML page
from the next page in a file.- Repeat until the
next button
can't be clicked anymore. - Quit.
Unfortunately the button persists even when it cannot be clicked. Here is the difference between the two:
When clickable:
<input type="image" id="OptionsBar1_imgNext" title="Next" src="/images/toolbaricons/nextsmall.gif" onclick="changeSelect(1);return false;" value="">
When not clickable:
<input type="image" id="OptionsBar1_imgNext" title="Next" src="/images/toolbaricons/disabled/nextsmall.gif" onclick="changeSelect(1);return false;" value="" disabled="" readonly="">
The number of pages is not consistent so I can't define a range of pages. I have had success running through and capturing HTML until the end, but can't get the driver to quit. I imagine this is because I'm not understanding the loop function correctly.
Here is what I have come up with:
with open('{}.html'.format(file_name), 'w', encoding = 'utf-8') as file:
file.write(driver.page_source)
while True:
driver.find_element(By.ID, "OptionsBar1_imgNext").get_attribute("src") is "/images/toolbaricons/nextsmall.gif"
driver.find_element(By.ID, "OptionsBar2_imgNext").click()
with open('{}.html'.format(file_name), 'a', encoding = 'utf-8') as file:
file.write(driver.page_source)
while False:
driver.find_element(By.ID, "OptionsBar1_imgNext").get_attribute("src") is "/images/toolbaricons/nextsmall.gif"
driver.quit()
I'm sure this is an elementary question and any help is appreciated!