Selenium/Python - 通过 css 选择器进行选择 [英] Selenium / Python - Selecting via css selector

查看:25
本文介绍了Selenium/Python - 通过 css 选择器进行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

无法从 css 选择器特定元素中进行选择.需要验证注册用户是否可以成功更改密码.我尝试了类的不同属性来调用它.结果是在尝试前两个示例时方法中出现异常错误.最后一次尝试调用第一个类实例并重置密码字段(失败).

Can not select from css selector specific element. Need to verify that the registered user can change their password successfully. I have tried the different attributes of the class to call it. The result is an exception error in the method when trying with the first two examples. The final try calls the first class instance and resets the password fields (fail).

尝试过:

driver.find_element_by_css_selector("value.Update").click()
driver.find_element_by_css_selector("type.submit").click()
driver.find_element_by_css_selector("input.test_button4").click()

目标:

我需要选择共享同一类的项目.如下所示,该类是共享的.

I need to select items that share the same class. As you can see below, the class is shared.

form id="changepw_form" name="changepw" action="#" method="post">
<div class="field3">
<div class="field3">
<div class="field3">
<input class="test_button4" type="reset" value="Reset" style"font-size:21px"="">
<input class="test_button4" type="submit" value="Update" style"font-size:21px"="">

推荐答案

driver.find_element_by_css_selector(".test_button4[value='Update']").click()

因为选择器需要 classidtagname,但 value.Update 本身不是这些.

Because the selector needs a class, id, or tagname, but value.Update by itself is none of these.

.test_button4 提供要匹配的类名,然后[value='Update'] 指定要选择的特定匹配项.

.test_button4 provides a classname to match against, and from there, [value='Update'] specifies which particular match(es) to select.

这篇关于Selenium/Python - 通过 css 选择器进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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