marcelo.delta
marcelo.delta

Reputation: 3082

Selenium python return html with __VIEWSTATE

Selenium python return html with __VIEWSTATE.

I'm trying to open a page with selenium and perform the submit. However, the imput id has another name.

Is this a limitation of selenium or something on the page?

This is the page. http://www8.receita.fazenda.gov.br/SimplesNacional/aplicacoes.aspx?id=21

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub',
         desired_capabilities=DesiredCapabilities.CHROME)

driver.get("http://www8.receita.fazenda.gov.br/SimplesNacional/aplicacoes.aspx?id=22")

#driver.find_element_by_id("Cnpj").send_keys("99999999999")
#inputElement.send_keys('99999999999')

print(driver.page_source)

driver.quit()

enter image description here

Upvotes: 0

Views: 200

Answers (1)

KunduK
KunduK

Reputation: 33384

The input element you are after is inside an iframe.You need to switch iframe first to access the input element.

Induce WebDriverWait() and wait for frame_to_be_available_and_switch_to_it()

Induce WebDriverWait() and wait for element_to_be_clickable()

Code:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

driver=webdriver.Chrome()
driver.get("http://www8.receita.fazenda.gov.br/SimplesNacional/aplicacoes.aspx?id=21")
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"frame")))
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.ID,'Cnpj'))).send_keys("99999999999")

Browser snapshot enter image description here

Upvotes: 1

Related Questions