Accessing elements on the next page in selenium python -
i trying write program in python3.5 using selenium automate downloading process in zbigz.com using firefox webdriver. code follows:
import time selenium import webdriver selenium.common.exceptions import timeoutexception #magnet link purpose of testing mag = "magnet:?xt=urn:btih:86259d1c8d9dfbe15b6290268231e68d414fed23&dn=the.big.bang.theory.s09e21.hdtv.x264-lol%5bettv%5d&tr=udp%3a%2f%2ftracker.openbittorrent.com%3a80&tr=udp%3a%2f%2fopen.demonii.com%3a1337&tr=udp%3a%2f%2ftracker.coppersurfer.tk%3a6969&tr=udp%3a%2f%2fexodus.desync.com%3a6969" def startdriver(): #starting firefox driver , waiting 100 seconds driver = webdriver.firefox() driver.implicitly_wait(100) return driver def download(driver, url, mg): #opening firefox @ url = www.zbigz.com driver.get(url) try: #accessing required elements on first page opens entry_box = driver.find_element_by_xpath('.//*[@id=\'text-link-input\']') go_button = driver.find_element_by_id('go-btn') #entering magnet link entry_box.clear() entry_box.send_keys(mg) #clicking on 'go' button go_button.click() #accessing free option free_button = driver.find_element_by_id('cloud-free-btn') #clicking on free option free_button.click() #now comes next page ('www.zbigz.com/myfiles') goes wrong while driver.find_elements_by_tag_name('html') none: #waiting page load continue #this button need click cloud_btn = driver.find_elements_by_xpath('.//*[@id=\'86259d1c8d9dfbe15b6290268231e68d414fed23\']/div[1]') #allowing time download gets cached time.sleep(60) #clicking cloud_btn.click() except timeoutexception: print('page not loaded. better connection!') if __name__=='__main__': #starting driver , downloading d = startdriver() download(d, zbigz, mag) time.sleep(30) d.quit()
however can't access button on next page. when run code error get:
traceback (most recent call last): file "g:/python/pycharm projects/torrentdownloader.py", line 88, in download(d, zbigz, mag) file "g:/python/pycharm projects/torrentdownloader.py", line 80, in download cloud_btn.click() attributeerror: 'list' object has no attribute 'click'
i beleive not able access elements on teh next page. , since submission method post, cannot use driver.get(zbigz+'myfiles')
.
so please suggest way access elements on page follows.
webdriver.find_elements_by_xpath
returns list of elements. if want 1 element, use webdriver.find_element_by_xpath
(no s
) instead:
cloud_btn = driver.find_element_by_xpath(".//*[@id='86259d1c8d9dfbe15b6290268231e68d414fed23']/div[1]")
btw, using ".."
string literal, don't need escape '
inside.
Comments
Post a Comment