简体   繁体   中英

Python selenium ElementNotInteractableException: Message: element not interactable

I am trying to login to beeradvocate.com to scrape (crawl) some beer data. I tried with selenium but have been brutally failing.

here is the html

<input type="text" name="login" value="" id="ctrl_pageLogin_login" class="textCtrl" tabindex="1" autofocus="autofocus" style="background-image: url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGP6zwAAAgcBApocMXEAAAAASUVORK5CYII=&quot;); cursor: auto;">

i tried using name and value and class but everything has failed. I attempted Xpath as my final try, but have failed as well.

website and inspection

My code:

driver=webdriver.Chrome("~~~~\\chromedriver.exe")
driver.get("https://www.beeradvocate.com/community/login/")

from selenium.common.exceptions import TimeoutException

driver.maximize_window()

    while True:
        try: 
            WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="ctrl_pageLogin_login"]'))).send_keys("scentmaster")
            break
        except TimeoutException: 
            print("too much time")

I've made the button work with:

button = driver.find_element_by_xpath('//*[@id="pageLogin"]/dl[3]/dd/input')
driver.execute_script("arguments[0].click();", button)

However, I need to be able to perform sent_keys to type in id and pw to log in... Anybody got some idea?

To feed the username, try this xpath:

'//form/dl/dd/input[@id="ctrl_pageLogin_login"]'

for the password:

'//form/dl/dd/input[@id="ctrl_pageLogin_password"]'

There are 2 fields on the page if you use xpath //*[@id = "ctrl_pageLogin_login"] , the input field you are referring to is the second. Sadly, the selenium find element by default refers to the first. It will work if you make it like this: (//*[@id = "ctrl_pageLogin_login"])[2] .

But I have another suggestion, try to locate element by css selector with this value: form#pageLogin input#ctrl_pageLogin_login

WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.CSS_SELECTOR,'form#pageLogin input#ctrl_pageLogin_login'))).send_keys("scentmaster")

#for password
driver.find_element_by_css_selector('form#pageLogin input#ctrl_pageLogin_password').send_keys('your_password')

#for submit
driver.find_element_by_css_selector('form#pageLogin input[type=submit]').click()
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.CSS_SELECTOR,'form#pageLogin input#ctrl_pageLogin_login'))).send_keys("scentmaster")

#for password
driver.find_element_by_css_selector('form#pageLogin input#ctrl_pageLogin_password').send_keys('your_password')

#for submit
driver.find_element_by_css_selector('form#pageLogin input[type=submit]').click()

The solution above given by frianH worked: :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM