Home > Enterprise >  Field not clearing Selenium/Python
Field not clearing Selenium/Python

Time:07-25

Any ideas on how to get the field to clear the pre-filled text prior to setting new text - I have attempted the previously recommended solutions and this is what I currently have - this merely just appends to the current pre-filled text:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait  
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
#Install Chrome Extension
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
#implicit wait
driver.implicitly_wait(0.5)
#maximize browser
driver.maximize_window()
#launch URL
driver.get("https://www.futbin.com/fut-card-creator/22")

#Set Vars
rating = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "rating_change")))
rating.click()
rating.send_keys(Keys.CONTROL   "a")
rating.send_keys(Keys.BACK_SPACE)
rating.send_keys("90")

driver.implicitly_wait(0.5)

position = driver.find_element(By.ID, "position_change")
position.click()
position.send_keys(Keys.CONTROL   "a")
position.send_keys(Keys.BACK_SPACE)
position.send_keys("ST")

CodePudding user response:

This is how you clear an input field in selenium (based on tyour existing code):

[...]
rating = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "rating_change")))
rating.click()
rating.clear() ## field will be cleared and you can input your value
[...]

CodePudding user response:

You can set the desired value within the desired element using 96

  • Related