简体   繁体   English

如何在WebElement中通过xpath查找子元素

[英]How to find a sub-element by xpath inside a WebElement

I'm trying to find a login form (with the two canonical user and password fields) in a web page with python and Selenium (the page is general so I cannot use the id of the field or the xpath in the specific site). 我正在尝试在带有python和Selenium的网页中找到登录表单(具有两个规范的用户名和密码字段)(该页面是通用的,因此我无法在特定站点中使用该字段的ID或xpath)。

To do so in a general way I get all the form in the webpage with 为此,我通常使用以下方式获取网页中的所有表格

for form in browser.find_elements_by_xpath('.//form'):

and than I want to find all the input fields with 比我想找到所有输入字段

for input_field in form.find_elemenents_by_xpath('.//input'):

but I get an error: 但我得到一个错误:

AttributeError: 'WebElement' object has no attribute 'find_elemenent_by_xpath'

Online I've found that I can use "find_element" on a webElement, but it not works. 在网上,我发现可以在webElement上使用“ find_element”,但是它不起作用。

Someone can help me? 有人可以帮我吗? thank you in advance! 先感谢您!

You have a typo in your code 您的代码中有错字

You entered elemenents instead of elements 您输入elemenents而不是elements

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

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