Python - Nested For Loop New Tab in Selenium -


i'm having trouble in running nested loop iterate 2 lists click through while opening new tabs , closing old one.

this code:

# loop w in agroecological_suitability_and_productivity_list:     # opens new tab     driver.execute_script("window.open()")     # switch newly opened tab     driver.switch_to.window(driver.window_handles[1])     # navigate new url in new tab     driver.get("http://www.gaez.iiasa.ac.at/w/ctrl?_flow=vwr&_view=type&idas=0&idfs=0&fieldmain=main_py_six&idps=0")     # click on agro-ecological suitability , productivity list     driver.find_element_by_css_selector('input[value="{}"]'.format(w)).click()     # click on crop link     driver.find_element_by_css_selector("input.linksubmit[value=\"▸ crop\"]").click()     aes_and_p = w     x in crop_list:         driver.find_element_by_css_selector('input[value="{}"]'.format(x)).click()         driver.switch_to.window(driver.window_handles[1])         # close current tab         driver.close()         # switch original tab         driver.switch_to.window(driver.window_handles[0]) 

for reason, error:

traceback (most recent call last):   file "c:\users\...\appdata\local\continuum\anaconda3\lib\site-packages\ipython\core\interactiveshell.py", line 2881, in run_code     exec(code_obj, self.user_global_ns, self.user_ns)   file "<ipython-input-63-1838894d3459>", line 102, in <module>     driver.find_element_by_css_selector('input[value="{}"]'.format(z)).click()   file "c:\users\...\appdata\local\continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 457, in find_element_by_css_selector     return self.find_element(by=by.css_selector, value=css_selector)   file "c:\users\...\appdata\local\continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 791, in find_element     'value': value})['value']   file "c:\users\...\appdata\local\continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 256, in execute     self.error_handler.check_response(response)   file "c:\users\...\appdata\local\continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response     raise exception_class(message, screen, stacktrace) selenium.common.exceptions.nosuchelementexception: message: no such element: unable locate element: {"method":"css selector","selector":"input[value="intermediate"]"}   (session info: chrome=60.0.3112.113)   (driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=windows nt 6.1.7601 sp1 x86_64) 

however, when use single loop, below, works:

# loop w in agroecological_suitability_and_productivity_list:     # opens new tab     driver.execute_script("window.open()")     # switch newly opened tab     driver.switch_to.window(driver.window_handles[1])     # navigate new url in new tab     driver.get("http://www.gaez.iiasa.ac.at/w/ctrl?_flow=vwr&_view=type&idas=0&idfs=0&fieldmain=main_py_six&idps=0")     # click on agro-ecological suitability , productivity list     driver.find_element_by_css_selector('input[value="{}"]'.format(w)).click()     # close current tab     driver.close()     # switch original tab     driver.switch_to.window(driver.window_handles[0]) 

any great.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -