[英]how to find element with specific class attributes using css selector or any other locator selenium python
Am trying to find an element using attribute in the same class,below is the element of the我正在尝试使用同一类中的属性查找元素,下面是
div class="outcome-pricedecimal " data-markettypecategory="00000000-0000-0000-da7a-000000580001" data-pd="1.66">1.66 </div>
I want to locate it using the data-pd="1.66" it the decimal number i need, because i want it to find the element if the decimal has changed to my prefered value(eg finding data-pd when =1.05) I tried finding it using this codes我想使用 data-pd="1.66" 它是我需要的十进制数来定位它,因为我希望它找到元素,如果十进制已更改为我的首选值(例如,当 =1.05 时查找 data-pd)我试过了使用此代码找到它
driver.find elements_by_xpath("//div[contains(number()
driver.find_elements_by_css_selector('div.data-pd="1.05)"and not:(.outcome-pricedecimal) (.data-markettypecategory="00000000-0000-0000-da7a-000000580001)"]')[0].click() driver.find_elements_by_css_selector('div.data-pd="1.05)" 而不是:(.outcome-priceecimal) (.data-markettypecategory="00000000-0000-0000-da7a-000000580001)"]')[0]。 ()
driver.find_element_by_css_selector(div.1.01) driver.find_element_by_css_selector(div.1.01)
thanks as you answer and help...感谢您的回答和帮助...
Just use BeautifulSoup
for this.只需使用
BeautifulSoup
。 Here is the code to do it using BeautifulSoup
:这是使用
BeautifulSoup
执行此操作的代码:
from bs4 import BeautifulSoup
html = '<div class="outcome-pricedecimal " data-markettypecategory="00000000-0000-0000-da7a-000000580001" data-pd="1.66">1.66 </div>'
soup = BeautifulSoup(html,'html5lib')
div = soup.find('div')
data_pd = div['data-pd']
print(data_pd)
Output:输出:
1.66
If you still wanna do it with selenium
, then you can do it like this:如果你仍然想用
selenium
来做,那么你可以这样做:
data_pd = driver.find_element_by_class_name("outcome-pricedecimal ").get_attribute('data-pd')
print(data_pd)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.