Span的Python Selenium CSS Selector get_attribute [英] Python Selenium CSS Selector by Span get_attribute

查看:45
本文介绍了Span的Python Selenium CSS Selector get_attribute的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经访问了一个网页,使用必需的参数填充了文本框和下拉列表,并提交了此信息(单击按钮),以便该网页可以执行计算.我正在尝试访问结果(文本值).结果应该是从最小到最大列出的计算列表,而我只希望最小值.我不确定我是否遇到计时问题或CSS选择器问题.

I have already accessed a webpage, populated text boxes and drop downs with required parameters, and submitted (button click) this information so the webpage can perform a calculation. I am trying to access the results (value of text). Results should be a list of calculations listed least to greatest, and I only want the lowest value. I am not sure if I am having a timing issue or a CSS Selector issue.

我尝试过:

e = driver.find_elements_by_css_selector("span[data-bind='calc']")
new = e[0].text
print(new)

错误:IndexError:列表索引超出范围

Error: IndexError: list index out of range

在尝试访问数据表中的计算元素之前,我想确保已完全填充数据表,并且我还尝试过:

I wanted to make sure the data table was being completely populated before I tried to access it's calculated elements, and I have also tried:

output_by_css = WebDriverWait(driver, 10).until(
lambda driver : driver.find_elements_by_css_selector('span.calc')
)

for output in (output_by_css):
    print(output.text)

错误:引发TimeoutException(消息,屏幕,堆栈跟踪)selenium.common.exceptions.TimeoutException:消息:

Error: raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:

有人可以帮助我按范围确定这是CSS选择器的问题还是计时问题,或者我还没有想到的其他问题?我该如何解决?

Can someone please help me determine if this is an issue with the CSS Selector by span or if it's a timing issue, or something else I have not yet thought of? How can I fix it?

推荐答案

您可以尝试应用以下选择器:

You can try applying the following selector:

driver.find_elements_by_css_selector('span[data-bind*=calc]')

在这里,我们得到所有具有 data-bind 属性的 span 标签,该标签的值内包含"calc".

Here we are getting all the span tags having data-bind attribute having "calc" inside the value.

这篇关于Span的Python Selenium CSS Selector get_attribute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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