Search code examples
pythonpython-3.xseleniumurlencode

How to use Python Selenium


I have a piece of HTML Code, which offers you to put your email in an input field after hitting a button (after clicking the button the textfield appears):

<div class="column-left w-col w-col-5">
<label class="radio-button-field-2 left w-radio">
<input type="radio" id="paypal" name="payout" value="paypal" data-name="payout" required="" class="w-form-formradioinput radio-button w-radio-input">
<span for="paypal" class="radio-button-label-2 w-form-label">PayPal-Konto</span>
</label>
</div>

<div class="block-payout-paypal" style="">
<input type="email" class="text-field-2 w-input" maxlength="256" name="paypal-email-2" data-name="Paypal Email 2" placeholder="[email protected]" id="paypal-email" required="">
</div>

My Goal now is to write a script which allows me to click on the button and then file out the input field. The website is: https://gruenkraft-zufriedenheit.de/ And the button I'm looking for is called: PayPal-Konto


Solution

  • When (PayPal-Konto) button is clicked, you would see a input, you can locate that with the help of below code.

    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.implicitly_wait(30)
    driver.get("https://gruenkraft-zufriedenheit.de/")
    wait = WebDriverWait(driver, 10)
    wait.until(EC.visibility_of_element_located((By.XPATH, "//span[text()='PayPal-Konto']"))).click()#ActionChains(driver).move_to_element(wait.until(EC.visibility_of_element_located((By.XPATH, "//span[text()='PayPal-Konto']")))).click().perform()
    wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input[name='paypal-email-2']"))).send_keys('[email protected]')
    

    Imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.action_chains import ActionChains