简体   繁体   English

Python selenium ElementNotInteractableException:消息:元素不可交互

[英]Python selenium ElementNotInteractableException: Message: element not interactable

I am trying to login to beeradvocate.com to scrape (crawl) some beer data.我正在尝试登录 beeradvocate.com 以抓取(抓取)一些啤酒数据。 I tried with selenium but have been brutally failing.我尝试使用 selenium 但一直失败。

here is the html这是 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.我尝试使用名称和值以及 class 但一切都失败了。 I attempted Xpath as my final try, but have failed as well.我尝试了 Xpath 作为我的最后一次尝试,但也失败了。

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?但是,我需要能够执行 sent_keys 以输入 id 和 pw 以登录...有人知道吗?

To feed the username, try this xpath:要输入用户名,试试这个 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.如果您使用 xpath //*[@id = "ctrl_pageLogin_login"] ,页面上有 2 个字段,您指的input字段是第二个。 Sadly, the selenium find element by default refers to the first.可悲的是,selenium find element默认指的是第一个。 It will work if you make it like this: (//*[@id = "ctrl_pageLogin_login"])[2] .如果您这样做,它将起作用: (//*[@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但我有另一个建议,尝试通过 css 选择器使用以下值定位元素: 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: :) frianH 给出的上述解决方案有效::)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 中的 Selenium:ElementNotInteractableException:消息:元素不可交互 - Selenium in Python: ElementNotInteractableException: Message: element not interactable ElementNotInteractableException:元素在 Selenium 中不可交互 - ElementNotInteractableException: element not interactable in Selenium ElementNotInteractableException:消息:元素不可交互 - ElementNotInteractableException: Message: element not interactable selenium.common.exceptions.ElementNotInteractableException:消息:使用Selenium和Python插入值时元素不可交互 - selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable while inserting value using Selenium and Python ElementNotInteractableException:消息:元素不是元素不可交互错误使用 Selenium 和 Python 将文本发送到 Email 字段 - ElementNotInteractableException: Message: element not element not interactable error sending text to Email field using Selenium and Python ElementNotInteractableException:消息:使用 Selenium 和 Python 将文本发送到 Quora 上的电子邮件字段时,元素不可交互错误 - ElementNotInteractableException: Message: element not interactable error while sending text to Email field on Quora using Selenium with Python ElementNotInteractableException:消息:使用 Selenium Python 在搜索字段中发送文本的元素不可交互错误 - ElementNotInteractableException: Message: element not interactable error sending text in search field using Selenium Python Selenium.common.exceptions.ElementNotInteractableException:消息:元素在离子框架中不可交互 - Selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable in ionic framework 发现 selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互 - Found selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable 错误是“selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互” - error is “selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM