V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
qanniu
V2EX  ›  问与答

v2ex 领金币页面 selenium find_elements_by_class_name 找不到元素求解

  •  
  •   qanniu · 2018-12-26 13:58:33 +08:00 · 1590 次点击
    这是一个创建于 1946 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如下丑陋的 code,用这样的语法找不到元素,不知为何 # button = driver.find_element_by_css_selector("li.'fa fa-ok-sign'") # button = driver.find_elements_by_class_name("fa fa-ok-sign")

    另外如何判断是否已经领过了:driver.find_element_by_css_selector 返回的是个 exception,没有 if else 方便. 不知怎么判断分支比较好.

    
    driver.get('https://www.v2ex.com/mission/daily')
    
    print "here stop -----"
    
    try:
    	button = driver.find_element_by_xpath("//input[@type='button' and @value='领取 X 铜币']")
    except NoSuchElementException as msg:
    	print u"no find the elecment: %s, may be has got the money? "%msg;
    	try:
    		button = driver.find_elements_by_xpath("//li[@class='fa fa-ok-sign']")
    		## 如下丑陋的 code,用这样的语法找不到元素,不知为何
    		# button = driver.find_element_by_css_selector("li.'fa fa-ok-sign'")
    		# button = driver.find_elements_by_class_name("fa fa-ok-sign")
    		
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4278 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 05:30 · PVG 13:30 · LAX 22:30 · JFK 01:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.