1

I've been trying to make a Python script to login into a certain website, navigate through the menu, fill out a form and save the file it generates to a folder.

I am having some problems to submit the form.

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


options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument('disable-infobars')
options.add_argument("--disable-extensions")

browser = webdriver.Chrome()
browser.get("https://directa.natal.rn.gov.br/")
WebDriverWait(browser, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"frame[name='mainsystem'][src^='main']")))
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.input[name='usuario']"))).send_keys("11844691000126")
browser.find_element_by_css_selector("input.input[name='senha']").send_keys("Link2007")
browser.find_element_by_css_selector("button.btn[name='acessar']").click()
1
  • 5
    I am having some problems to submit de form Explain the problems. Commented May 2, 2019 at 15:43

2 Answers 2

1

Once you fill up the required fields then to submit the form you can use the following solution:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    options = webdriver.ChromeOptions()
    options.add_argument("start-maximized")
    # options.add_argument('disable-infobars')
    options.add_argument("--disable-extensions")
    driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
    driver.get("https://directa.natal.rn.gov.br/")
    WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"frame[name='mainsystem'][src^='main']")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.input[name='usuario']"))).send_keys("11844691000126")
    driver.find_element_by_css_selector("input.input[name='senha']").send_keys("Link2007")
    driver.find_element_by_css_selector("button.btn#acessar").click()
    
  • Browser Snapshot:

directa

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! It is not working on Chrome, but it is working on Firefox. I dont Know why.
0

You have to switch to the iframe, because your element is not in the main website, is inside iframe.

iframes = browser.find_elements_by_xpath("//iframe[@name='mainsystem']")
print("Iframes: %s" %len(iframes))
browser.switch_to_frame(iframes[0])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.