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

2018-12-26 13:58:33 +08:00
 qanniu

如下丑陋的 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")
		
1594 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/521158

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX