Javascript Can';t使用python selenium登录到namecheap
您好,我正在尝试使用selenium登录namescape.com,但无法选择登录表单。我在选择元素时出错:Javascript Can';t使用python selenium登录到namecheap,javascript,python,selenium,selenium-webdriver,Javascript,Python,Selenium,Selenium Webdriver,您好,我正在尝试使用selenium登录namescape.com,但无法选择登录表单。我在选择元素时出错: selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with 但是我可以看到我选择了ok这个xpath。 这是我的密码: from selenium import webdriver fr
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
但是我可以看到我选择了ok这个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">
你能帮我吗?
谢谢看来您的xPath定位器(用于登录/用户名)是失败的原因 尝试使用以下CSS定位器
Username
css=div.group > input[name="LoginUserName"]
Password
css=div.group > input[name="LoginPassword"]
通常,xPath定位器被认为比CSS定位器更脆弱。因此,最好使用CSS定位器。您的xPath定位器(用于登录/用户名)似乎是失败的原因 尝试使用以下CSS定位器
Username
css=div.group > input[name="LoginUserName"]
Password
css=div.group > input[name="LoginPassword"]
通常,xPath定位器被认为比CSS定位器更脆弱。因此,使用CSS定位器将是一件好事。您导入了
WebDriverWait
和预期条件
,但您没有使用它们
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//input[@name='LoginUserName']")).send_keys(username)
这将等待10秒钟,元素才可见。您导入了
WebDriverWait
和预期的\u条件,但未使用它们
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//input[@name='LoginUserName']")).send_keys(username)
这将等待10秒钟,元素才会可见。否…我遇到了相同的错误-与驱动程序相同。通过“css”选择器(“input[name=“LoginUserName”]”)查找“元素”。发送键('aaaaa')使用的是整个css选择器。很高兴它现在能为您工作:)不……我在驱动程序中遇到了相同的错误。通过“css”选择器(“输入[name=“LoginUserName”]”)查找“元素”。发送键('aaaaa')使用的是整个css选择器。很高兴它现在能为你工作:)我纠正了我的代码测试,如果答案是好的。谢谢,我更正了我的代码测试,如果答案是正确的。非常感谢。