嗨我想用selenium登录到namecheap.com,但无法选择登录表单。我选择元素时出现这个错误:无法用python selenium登录到namecheap
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
但我可以看到我选择了好的xpath。 这里是我的代码:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common import action_chains
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
cookie_file_path = 'cookie.txt'
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] =("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36")
# driver = webdriver.PhantomJS(desired_capabilities=dcap,service_args=['--ssl-protocol=any','--ignore-ssl-errors=true','--cookies-file={}'.format(cookie_file_path)])
driver=webdriver.Firefox()
driver.set_window_size(1024, 768)
username='test'
password='test123'
driver.get('https://www.namecheap.com/myaccount/login.aspx')
driver.find_element_by_xpath("//input[@name='LoginUserName']").send_keys(username)
driver.find_element_by_xpath('//input[@name="LoginPassword"]').send_keys(password)
loginButtonXpath = "//input[@type='submit']"
driver.find_element_by_xpath(loginButtonXpath).click()
driver.save_screenshot('testing.png')
这里是HTML:
<div class="sign-in-form">
<fieldset>
<input type="text" name="LoginUserName" title="Username" placeholder="Username" autocapitalize="off" autocorrect="off" class="input removespecialchars handlereturn" maxlength="20" />
<input type="password" name="LoginPassword" title="Password" placeholder="Password" class="input handlereturn" maxlength="100" />
<input type="hidden" name="hidden_LoginPassword" />
<a href="https://www.namecheap.com/myaccount/login.aspx" id="ctl00_ctl00_ctl00_ctl00_base_content_web_base_content_topNavLoginLink" class="head-loginb ncRedirectButton btn sign-in-btn btn-block" rel="nofollow">Sign In</a>
<a href="https://ap.www.namecheap.com/ResetPassword" id="ctl00_ctl00_ctl00_ctl00_base_content_web_base_content_passwordRemiderLink" title="Password Reminder">Forgot your password?</a>
</fieldset>
</div>
</div>
</li>
<li class="hidewhenloggedin"><a href="/myaccount/signup.aspx">Sign Up</a></li>
<li class="expandable signed-in hidewhennotloggedin user-menu">
你能帮助我吗? 谢谢
No ...我得到了同样的错误 - 与driver.find_element_by_css_selector('input [name =“LoginUserName”]')。send_keys('aaaaa') –
Ahh ...我的坏...现在工作.. 。非常感谢你! –
键是使用整个CSS选择器。很高兴它适合你:) – TestingWithArif