Home > other >  I cant type text into placeholder using Selenium send_key
I cant type text into placeholder using Selenium send_key

Time:02-24

I cant input the text in to the placeholder in Weight, length, width and height.

It doesnt work for .send_keys(). It stay in the placeholder and do nothing!!

Can someone help me solve it? I cant figure it out!!!

from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from time import sleep
import pandas as pd


chrome_options = Options()
# chrome_options.add_argument("--headless")
chrome_options.add_experimental_option("detach", True)

driver = webdriver.Chrome(ChromeDriverManager().install(),options=chrome_options)
driver.get("https://calculator.shipany.io/")
wait = WebDriverWait(driver, 5)

dropdownOrigin = wait.until(EC.visibility_of_element_located((By.XPATH, "//div[@class='booking-form']//select[.//option[contains(.,'Origin')]]")))
selectOrigin = Select(dropdownOrigin)
selectOrigin.select_by_visible_text("Hong Kong")

dropdownDestination = wait.until(EC.visibility_of_element_located((By.XPATH, "//div[@class='booking-form']//select[.//option[contains(.,'Destination')]]")))
selectDest = Select(dropdownDestination)
selectDest.select_by_visible_text("Hong Kong")

weight = wait.until(EC.visibility_of_element_located((By.XPATH, "//*[@id='i_form']/div/div[2]/div[3]/input[1]")))
weight.send_keys("1")

length = wait.until(EC.visibility_of_element_located((By.XPATH, "//*[@id='dimension']/input[2]")))
length.send_keys("1")

width = wait.until(EC.visibility_of_element_located((By.XPATH, "//*[@id='dimension']/input[3]")))
width.send_keys("1")

height = wait.until(EC.visibility_of_element_located((By.XPATH, "//*[@id='dimension']/input[6]")))
height.send_keys("1")

button = wait.until(EC.visibility_of_element_located((By.XPATH, "//*[@id='i_form']/div/div[2]/div[5]/button[1]")))
button.click()

CodePudding user response:

Well the reason it is not working because of style attribute.It is saying display: none; you need to change the style of the element to display: block; in order to access the element.

Use java script executor to change the style of the element.

enter image description here

driver.get("https://calculator.shipany.io/")
wait=WebDriverWait(driver, 5)
dropdownOrigin =wait.until(EC.visibility_of_element_located((By.XPATH, "//div[@class='booking-form']//select[.//option[contains(.,'Origin')]]")))
selectOrigin=Select(dropdownOrigin)
selectOrigin.select_by_visible_text("Hong Kong")

dropdownDestination =wait.until(EC.visibility_of_element_located((By.XPATH, "//div[@class='booking-form']//select[.//option[contains(.,'Destination')]]")))
selectDest=Select(dropdownDestination)
selectDest.select_by_visible_text("Hong Kong")

weight=wait.until(EC.presence_of_element_located((By.XPATH, "//input[@placeholder='Weight(kg)*']/following::input[1]")))
driver.execute_script("arguments[0].style.display = 'block';",weight)
weight.send_keys("1")

length=wait.until(EC.presence_of_element_located((By.XPATH, "//input[@placeholder='L(cm)']/following::input[1]")))
driver.execute_script("arguments[0].style.display = 'block';",length)
length.send_keys("1")

width=wait.until(EC.presence_of_element_located((By.XPATH, "//input[@placeholder='W(cm)']/following::input[1]")))
driver.execute_script("arguments[0].style.display = 'block';",width)
width.send_keys("1")

Height=wait.until(EC.presence_of_element_located((By.XPATH, "//input[@placeholder='H(cm)']/following::input[1]")))
driver.execute_script("arguments[0].style.display = 'block';",Height)
Height.send_keys("1")
  • Related