[英]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("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGP6zwAAAgcBApocMXEAAAAASUVORK5CYII="); 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 作为我的最后一次尝试,但也失败了。
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.