简体   繁体   English

使用Python + Selenium WebDriver选择一个段落

[英]Select a paragraph with Python + Selenium WebDriver

How to select a paragraph using Python + Selenium? 如何使用Python + Selenium选择段落? I do the search in an input of my site, after my API return my products, I would like to click on some product, however, they are all being rendered inside a div, with the same class, since it is a for in an application SPA, how do I select the product by clicking on the paragraph of the title of the product and all have the same classes? 我在网站的输入中进行搜索,当我的API返回我的产品后,我想单击某些产品,但是,它们都是在div中以相同的类呈现的,因为它是在应用SPA,如何通过单击产品标题的段落来选择产品,并且它们都具有相同的类?

from selenium import webdriver
import time

options = webdriver.ChromeOptions()
options.binary_location = "/usr/bin/chromium"
driver = webdriver.Chrome(executable_path="./chromedriver")
driver.get("www.mysite.com.br")

select_button_input = driver.find_element_by_class_name("button-search")

select_input = driver.find_element_by_css_selector("input[type='text']")
select_input.send_keys("Iphone")
select_button_input.click()

Below is what I want to select from my site: My site with products and class in my div of products . 以下是我要从网站中选择的内容: 我的网站包含产品和产品类别中的类

Please try this.It should work. 请尝试此操作。

element=driver.find_element_by_xpath("//p[@class='card-text text-truncate']").text
print(element)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM