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")
-
I woke up this morning and it is suddenly working... I am not sure why it wasn't working yesterday but it is functioning fine this morningDevin Smith– Devin Smith2022年07月25日 07:53:28 +00:00Commented Jul 25, 2022 at 7:53
2 Answers 2
This is how you clear an input field in selenium (based on your 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
[...]
answered Jul 24, 2022 at 22:03
Sign up to request clarification or add additional context in comments.
1 Comment
Devin Smith
I can confirm this does work aswell, when I tested this last night it wasn't functioning so went the CTRL A DEL route but yes this does work and is shorter!
You can set the desired value within the desired element using setAttribute()
method as follows:
Code block:
driver.execute("get", {'url': 'https://www.futbin.com/fut-card-creator/22'}) WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[aria-label='dismiss cookie message']"))).click() driver.execute_script("arguments[0].setAttribute('value','96')", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#rating_change"))))
Browser snapshot:
answered Jul 24, 2022 at 22:06
3 Comments
undetected Selenium
Nopes :) correct place. OP asked "how to get the field to clear the pre-filled text", user input is accomodated within
value
attribute, so you can set it directly.Devin Smith
This does indeed replace the pre-filled out value, however, does not trigger the change on the card face on the left - need to trigger the send_keys in order to get it to trigger the card change
undetected Selenium
Never mind, you seem to get a working solution ;)
lang-py