0

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")
asked Jul 24, 2022 at 21:55
1
  • 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 morning Commented Jul 25, 2022 at 7:53

2 Answers 2

1

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

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!
0

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:

96

answered Jul 24, 2022 at 22:06

3 Comments

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.
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
Never mind, you seem to get a working solution ;)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.