0

With the following code, I am able to open a web page and retrieve its contents.

Based on this web page contents, I would like to execute a post on this page where I supply some form data.

How can this be done with the selenium / chromedriver api?

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

browser = webdriver.Chrome(executable_path=r"/usr/local/share/chromedriver")

url = r'https:\\somewebpage.com'
result = browser.get(url)
user7468395
  • 1,299
  • 2
  • 10
  • 23

1 Answers1

1

I don't think this is possible with selenium alone.

What you could do is fill the form / click on the submit button with something like this:

input_a = driver.find_element_by_id("input_a")
input_b = driver.find_element_by_id("input_b")

input_a.send_keys("some data")
input_b.send_keys("some data")

driver.find_element_by_name("submit").click()

If you really want to create the POST request yourself, you should look into the https://github.com/cryzed/Selenium-Requests package, which will allow you to create POST requests just like the Requests package but with Selenium.

ksahin
  • 206
  • 1
  • 7