from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver')
NOME = (By.ID, "txtLogin")
PASS = (By.ID, "txtSenha")
SUBMIT = (By.CSS_SELECTOR, "input[type=\"button\"]")
MENU1= (By.XPATH, "html/body/div[1]/div[6]")
MENU2 = (By.XPATH, "html/body/div[5]")
driver.get('https://www.comprasnet.gov.br/seguro/loginPortal.asp')
driver.implicitly_wait(5)
selecao = Select(driver.find_element_by_name("perfil"))
selecao_opcao = selecao.options
selecionado = selecao.select_by_index(1)
driver.find_element(*NOME).clear()
login = driver.find_element(*NOME).send_keys("******")
password = driver.find_element(*PASS).send_keys("*******")
botao_submit = driver.find_element(*SUBMIT).click()
#pega o ID da janela atual
window_principal = driver.window_handles[0]
print(window_principal)
window_secundario = driver.window_handles[1]
print(window_secundario)
driver.switch_to_window(window_secundario)
driver.close(window_secundario)
/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/bin/python3.6 "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 54673 --file /Users/luribeiro/PycharmProjects/scriptspy/cry.py
pydev debugger: process 1550 is connecting
Connected to pydev debugger (build 172.3968.37)
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1599, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1026, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/luribeiro/PycharmProjects/scriptspy/cry.py", line 44, in <module>
window_secundario = driver.window_handles[1]
IndexError: list index out of range
Process finished with exit code 1
Desde já agradeço.
Abraço.