使用Selenium和python查找一种特殊的按钮 [英] Find a special kind of buttons with selenium and python
问题描述
我想用以下代码从linkedin页面中单击一个按钮:
<a class="vcard-button bt-connect bt-primary" href="#"><span> </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> </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屋!