[英]Selenium can't find elements
I am trying to login to a site through Selenium. 我正在尝试通过Selenium登录到站点。 All the sites on which I try to log in, I could do this less.
我尝试登录的所有站点,我可以做得更少。 After putting this part of the code shows me a Python 2.7 error:
放置这部分代码后,向我展示了Python 2.7错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 350, in send_keys
'value': keys_to_typing(value)})
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 499, in _execute
return self._parent.execute(command, params)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 297, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.32.498537 (cb2f855cbc7b82e20387eaf9a43f6b99b6105061),platform=Mac OS X 10.12.6 x86_64)
Code: 码:
# coding=utf-8
from selenium import webdriver
driver = webdriver.Chrome('/Users/Martin/Desktop/chromedriver')
driver.get("https://car.com")
user= driver.find_element_by_xpath('//*[@id="onevideo_login_username"]')
user.send_keys("email")
Inspect: 检查:
<input type="text" id="onevideo_login_username" name="adaptv_email" data-i18n-placeholder="login.username" ng-model="models.login.email" class="ng-pristine ng-valid" placeholder="Username">
As I said before, I can login in all web sites I was trying, but this one is a headache! 正如我之前所说,我可以登录我尝试过的所有网站,但这是一个令人头疼的问题!
If you have id,then its better to use, 如果您有ID,那么最好使用它,
Try: 尝试:
user=driver.find_element_by_id('onevideo_login_username');
Please check the URL, I guess your URL is not correct. 请检查网址,我想您的网址不正确。 First of all I did not find any element like this in URL, but as per html I suggest you locator to locate element
首先,我没有在URL中找到任何类似的元素,但是根据html,我建议您使用定位器来定位元素
<input type="text" id="onevideo_login_username" name="adaptv_email" data-i18n-placeholder="login.username" ng-model="models.login.email" class="ng-pristine ng-valid" placeholder="Username">
Use ID 使用编号
user=driver.find_element_by_id('onevideo_login_username');
Use Name 使用名称
user=driver.find_element_by_name('adaptv_email');
Use xpath 使用xpath
user= driver.find_element_by_xpath('//*[@name="adaptv_email"]')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.