python – Selenium Webdriver – Select Drop down, input text and click
I got error: AttributeError: ‘WebDriver’ object has no attribute ‘find_element_by’
url = "https://calculator.shipany.io/"
chrome_options = Options()
# chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options=chrome_options)
driver.get(url)
sleep(5)
1.) How to use selenium to select drop down:
- Select “Hong Kong” in Origin
origin = driver.find_element_by(By.XPATH, "//*[@id='i_form']/div/div[2]/div[1]/select/option[2]")
origin.click()
- Select “Hong Kong” in Destination
destination = driver.find_element_by(By.XPATH, "//*[@id='i_form']/div/div[2]/div[2]/select/option[2]")
destination.click()
2.) How to input text in the placeholder of
weight = driver.find_element_by(By.XPATH, "//*[@id='i_form']/div/div[2]/div[3]/input[1]")
weight.send_keys("1")
length = driver.find_element_by(By.XPATH, "//input[@placeholder="L(cm)"]")
length.send_keys("1")
width = driver.find_element_by(By.XPATH, "//*[@id='dimension']/input[3]")
width.send_keys("1")
height = driver.find_element_by(By.XPATH, "//*[@id='dimension']/input[6]")
height.send_keys("1")
3.) How to click the button for submit-form?
button = driver.find_element_by(By.XPATH, "//*[@id='i_form']/div/div[2]/div[5]/button[1]")
button.click()
Read more here: Source link