使用Selenium和python查找一种特殊的按钮 [英] Find a special kind of buttons with selenium and python

查看:144
本文介绍了使用Selenium和python查找一种特殊的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用以下代码从linkedin页面中单击一个按钮:

<a class="vcard-button bt-connect bt-primary" href="#"><span>&nbsp;</span>Connect</a>

使用此代码driver.find_elements_by_css_selector("a [class ='vcard-button bt-connect bt-primary']")我可以找到元素,但是当我尝试单击它们时,我收到一条消息,指出该对象不是无法点击.我在做什么错了?

解决方案

从您提供的有限信息来看,问题似乎是由于find_elements引起的,请注意

此:

code driver.find_elements_by_css_selector("a[class='vcard-button bt-connect bt-primary']")

返回网络元素列表.

所以您可能想做的是

connect = code driver.find_element_by_css_selector("a[class='vcard-button bt-connect bt-primary']")
connect.click()

connect_buttons = code driver.find_elements_by_css_selector("a[class='vcard-button bt-connect bt-primary']")
# Assuming the first index in the returned list of web elements contains the Webelement
# You want to interact with 
connect_buttons[0].click() 

I want to click in one button from the linkedin page with this code:

<a class="vcard-button bt-connect bt-primary" href="#"><span>&nbsp;</span>Connect</a>

With this code driver.find_elements_by_css_selector("a[class='vcard-button bt-connect bt-primary']") i can find the elements but when i try to click them i get a message saying that the object isn't clickable. What i'm doing wrong?

解决方案

From the limited information that you have provided seems like the problem is because of find_elements, note the 's'

This:

code driver.find_elements_by_css_selector("a[class='vcard-button bt-connect bt-primary']")

returns a list of webelements.

So what you might want to do is

connect = code driver.find_element_by_css_selector("a[class='vcard-button bt-connect bt-primary']")
connect.click()

Or

connect_buttons = code driver.find_elements_by_css_selector("a[class='vcard-button bt-connect bt-primary']")
# Assuming the first index in the returned list of web elements contains the Webelement
# You want to interact with 
connect_buttons[0].click() 

这篇关于使用Selenium和python查找一种特殊的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆