0

I keep getting the error: AttributeError: 'NoneType' object has no attribute 'send_keys'

I believe the error happens because I cannot navigate to the field. This is the xpath=

('//*[@id="content"]/div/div[2]/div[2]/form/div[1]/div[1]/div/input')

I cannot seem to get the field.

Here's the html

<div class="containerInput" ng-class="{'error': userSelectedAgeInvalid || userSelectedAgeMissing || userSelectedAgeNotNumber}">
                            <div class="title">Din alder</div>
                            <input afocus="true" tabindex="1" type="text" ng-model="userSelectedAge" ng-blur="timeIt('userSelectedAge')" class="ng-isolate-scope ng-valid ng-dirty">
                            <small ng-show="userSelectedAgeInvalid" class="error alt ng-binding ng-hide">Indtast alder mellem 18 og 120 år</small>
                            <small ng-show="userSelectedAgeMissing" class="error alt ng-hide">Du skal angive en alder</small>
                            <small ng-show="userSelectedAgeNotNumber" class="error alt ng-binding ng-hide">Feltet må kun indeholde tal</small>
                        </div>

And here's my code

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-gpu")

# enable browser logging
d = DesiredCapabilities.CHROME
d['loggingPrefs'] = { 'browser':'ALL' } 
driver = webdriver.Chrome(desired_capabilities = d, options=chrome_options)
driver.fullscreen_window()

wait = WebDriverWait(driver,1)

#URL
driver.get("https://forsikringsguiden.dk/#!/bilforsikring/omdig")

#remove cookie bar
driver.find_element_by_id('cookieBarAccept').click()         


#Below is my different attempts. 

#driver.find_element_by_css_selector("input[type='text']").click().send_keys("50")

#wait.until(EC.element_to_be_clickable(By.BycssSelector,'//*[@id="content"]/div/div[2]/div[2]/form/div[1]/div[1]/div')).click().send_keys("50")

element = wait.until(EC.element_to_be_clickable((By.XPATH,'//*[@id="content"]/div/div[2]/div[2]/form/div[1]/div[1]/div/input')))
element.find_element_by_xpath('//*[@id="content"]/div/div[2]/div[2]/form/div[1]/div[1]/div/input').click().send_keys("50")

1 Answer 1

1

Please try the below code. After finding an element with the visibility_of_all_elements_located you need to specify what action you are going to perform on that element like: sendkey, click

   wait = WebDriverWait(driver, 10)
   element =  wait.until(EC.presence_of_element_located((By.XPATH, "//*[@id="content"]/div/div[2]/div[2]/form/div[1]/div[1]/div/input")))
   element.send_keys("50")
Sign up to request clarification or add additional context in comments.

3 Comments

i added some to the code: element.click().send_keys("50") testing now
Just tried. Didn't work :( It doesn't click the field
it gives me an error "AttributeError: 'list' object has no attribute 'send_keys'"

Your Answer

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.