Select an input element using Selenium
This will click on the login button on moodle.tau.ac.il page. The line driver.find_element_by_xpath(".//*[@id='login']/div/input").click()
finds the login button on the page and clicks it. Xpath is just a selector type that you can use with selenium to find web elements on a page. You can also use ID, classname, and CSSselectors.
from selenium import webdriverdriver = new webdriver.Chrome()driver.get('moodle.tau.ac.il')# This will take you to the login page.driver.find_element_by_xpath(".//*[@id='login']/div/input").click()# Fills out the login pageelem = driver.find_element_by_xpath("html/body/form/table/tbody/tr[2]/td/table/tbody/tr[1]/td[2]/input")elem.send_keys('Your Username')elem = driver.find_element_by_xpath("html/body/form/table/tbody/tr[2]/td/table/tbody/tr[3]/td[2]/input")elem.send_keys('Your ID Number')elem = driver.find_element_by_xpath("html/body/form/table/tbody/tr[2]/td/table/tbody/tr[1]/td[2]/input")elem.send_keys('Your Password')driver.find_element_by_xpath("html/body/form/table/tbody/tr[2]/td/table/tbody/tr[7]/td[2]/input").click()
The page has two identical login forms and your XPath returns the hidden one.So with the visible one:
from selenium import webdriverdriver = webdriver.Chrome()driver.get(r"http://moodle.tau.ac.il/")driver.find_element_by_css_selector("#page-content #login input[type=submit]").click()
Or with an XPath:
from selenium import webdriverdriver = webdriver.Chrome()driver.get(r"http://moodle.tau.ac.il/")driver.find_element_by_xpath("id('page-content')//form[@id='login']//input[@type='submit']").click()