选择密码文本框后,将.sendkeys设置为麻烦,我看到光标闪烁,等待输入一些文本
这是html
<div class="hm-Login ">
<div class="hm-Login_UserNameWrapper ">
<input type="text" class="hm-Login_InputField ">
<div class="hm-Login_InputText ">Join</div>
</div>
<div class="hm-Login_PasswordWrapper ">
<input type="text" class="hm-Login_InputField ">
<input type="password" class="hm-Login_InputField Hidden ">
<button tabindex="0" class="hm-Login_LoginBtn ">GO</button>
<div class="hm-Login_InputText ">Lost Login?</div>
</div>
</div>
这是我的代码
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from selenium import webdriver
driver = webdriver.Chrome("xxxxx/chromedriver")
driver.get('https://www.bet365.com.au/#/HO/');
driver.find_element_by_xpath("//*[@id='TopPromotionBetNow']").click()
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//input[@type='text']"))).click()
driver.find_element_by_class_name("hm-Login_InputField").click()
#time.sleep(5) # Let the user actually see something!
#username
elem = driver.find_element_by_class_name("hm-Login_InputField")
elem.click()
elem.clear()
elem.send_keys("xxxx")
#password
elem = driver.find_element_by_xpath("//div[@class='hm-Login_PasswordWrapper ']//input[@type='text']")
#elem = driver.find_element_by_xpath("//input[@type='text']")
elem.clear()
elem.click()
#attempt 1
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='hm-Login_PasswordWrapper ']//input[@type='text']"))).send_keys("xx")
#attempt 2
driver.implicitly_wait(10) # seconds
elem.send_keys("xxxxx!")
这是错误 ElementNotInteractableException:元素不可交互
感谢您的帮助。 您可以在代码底部看到我的尝试...
答案 0 :(得分:0)
XPATH正在获取type = text的元素。单击此元素类名称后,将立即附加“隐藏”,这就是为什么当尝试在此元素中输入文本时会出现此错误的原因。尝试以下解决方案,首先单击具有type = text的元素,然后清除并将键发送到其同级元素(type = password)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='hm-Login_PasswordWrapper ']//input[@type='text']"))).click()
# Now, Enter text into element with type=password attribute
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@class,'hm-Login_PasswordWrapper ')]//input[@type='password']"))).clear()
driver.find_element_by_xpath("//div[@class='hm-Login_PasswordWrapper ']//input[@type='text']").send_keys("xxxxx!")
我用Java测试了它,并且工作正常。抱歉,我目前没有Python,但是应该可以。
答案 1 :(得分:0)
在指定驱动程序后添加以下内容似乎已解决了问题,.send_keys(“ xxxx”)现在可以正常使用了
driver.implicitly_wait(15)
http://allselenium.info/wait-for-elements-python-selenium-webdriver/