ssyybb2005 发表于 2016-12-1 16:34:21

元素找到了,但是该如何操作,好像不可以点击

本帖最后由 ssyybb2005 于 2016-12-1 17:01 编辑

<a class="W_btn_a btn_34px " tabindex="6" suda-data="key=tblog_weibologin3&value=click_sign" node-type="submitBtn" action-type="btn_submit" href="javascript:void(0)">
<em>登录</em>

也不可以提交submit()
有什么办法可以打开链接吗
以下是脚本
# encoding:utf-8
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest,time,re

class Mysmalltest(unittest.TestCase):
    def setUp(self):
      self.driver = webdriver.Chrome()
      self.base_url = "http://www.weibo.com"
      self.verificationErrors = []
      self.accept_next_alert = True
   
    def test_mysmall(self):
      driver = self.driver
      driver.get(self.base_url + "/")
      time.sleep(3)
      driver.find_element_by_link_text(u"登录").click()
      time.sleep(2)
      # se=driver.find_element_by_xpath("//*[@id='layer_14805670754181']/div/div/div/div/input")
      # se=driver.find_element_by_xpath("/html/body/div/div/div/div/div/input")
      # se=driver.find_element_by_xpath("//input[@class='W_input' and @name='username']")
      se=driver.find_element_by_xpath("(//input[@name='username'])")
      se.clear()
      # st=driver.find_element_by_xpath("//input[@name='username']")
      # print st
      se.send_keys("1781")
      driver.find_element_by_xpath("(//input[@name='password'])").clear()
      driver.find_element_by_xpath("(//input[@name='password'])").send_keys("00000")
      # driver.find_element_by_xpath("//div[@id='layer_14805667737221']/div/div/div/div/a").click()
      sz=driver.find_element_by_xpath(u"(//a[.='登录'])").click()
      sz.click()   这里报错
      
      time.sleep(3)
sz=driver.find_element_by_xpath(u"(//a[.='登录'])")      这个是定位代码
求大神帮解惑


错误提示
Traceback (most recent call last):
File "C:\Users\syb\Desktop\mysmalltest.py", line 34, in test_mysmall
    sz=driver.find_element_by_xpath(u"(//a[.='鐧诲綍'])").click()
File "D:\Python27\lib\site-packages\selenium-2.45.0-py2.7.egg\selenium\webdriver\remote\webelement.py", line 65, in click
    self._execute(Command.CLICK_ELEMENT)
File "D:\Python27\lib\site-packages\selenium-2.45.0-py2.7.egg\selenium\webdriver\remote\webelement.py", line 402, in _execute
    return self._parent.execute(command, params)
File "D:\Python27\lib\site-packages\selenium-2.45.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 175, in execute
    self.error_handler.check_response(response)
File "D:\Python27\lib\site-packages\selenium-2.45.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 166, in check_response
    raise exception_class(message, screen, stacktrace)
ElementNotVisibleException: Message: element not visible
(Session info: chrome=54.0.2840.59)
(Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 6.1.7601 SP1 x86_64)




若尘_51 发表于 2016-12-1 16:50:49

脚本加上报错的信息附上来看看~~

若尘_51 发表于 2016-12-2 08:33:17

为啥有两个click()?去掉第一个.click()
sz=driver.find_element_by_xpath(u"(//a[.='登录'])").click()
sz.click()   这里报错
页: [1]
查看完整版本: 元素找到了,但是该如何操作,好像不可以点击