简体   繁体   English

硒提取…需要提取由CSS选择器定位的元素的文本

[英]Selenium Extraction…Need to extract text of element located by CSS Selector

I am having a very frustrating time trying to figure out what is going on. 我正在非常沮丧的时间试图弄清楚发生了什么。 My code was working last week, but for whatever reason I am not getting any results any more. 我的代码上周工作正常,但是由于任何原因,我再也没有得到任何结果。 I am getting a timeout message when searching for the css selector "h3.one" on the website. 在网站上搜索CSS选择器“ h3.one”时,收到超时消息。 My code is supposed to find all elements with that css selector and of those elements, return the one that is diplayed. 我的代码应该找到具有该CSS选择器的所有元素,并返回那些被显示的元素。

I need help especially with the implicit wait 我需要帮助,尤其是在隐式等待中

Here is my code: 这是我的代码:

browser = webdriver.Firefox()
browser.get('https://www.voilanorbert.com/')
inputElement = browser.find_element_by_id("form-search-name")
inputElement.send_keys(leadslist[i][0])
inputElement = browser.find_element_by_id("form-search-domain")
inputElement.send_keys(leadslist[i][1])
searchbutton = browser.find_element_by_name("search")
searchbutton.click()

wait = WebDriverWait(browser, 20)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "h3.one")))
h3s = browser.find_elements_by_css_selector('h3.one')
h3 = next(element for element in h3s if element.is_displayed())
result = h3.text
print (result)

The print is only for the purpose to see what is being extracted/make sure that it is actually doing what is needed. 印刷品仅用于查看正在提取的内容/确保其实际在执行所需的操作。

There is an another h3 element with class="one" which is really invisible. 还有一个带有class="one" h3元素,它实际上是不可见的。 This element is messing things up. 这个元素使事情变得混乱。

Either make your selector specific to the "success" container (works for me): 要么使选择器特定于“成功”容器(对我有用):

div#result-success h3.one

or wait for the results block to appear: 或等待results块出现:

div.results

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

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