qanniu
V2EX  ›  问与答

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

  •  
  •   qanniu · Dec 26, 2018 · 1925 views
    This topic created in 2694 days ago, the information mentioned may be changed or developed.

    如下丑陋的 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")
    		
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5696 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 07:02 · PVG 15:02 · LAX 00:02 · JFK 03:02
    ♥ Do have faith in what you're doing.