Get all Elements in a Form

后端 未结 4 1316
渐次进展
渐次进展 2021-02-02 14:56

I would like to use Selenium to submit a form which contains several elements. For example:

4条回答
  •  后悔当初
    2021-02-02 15:25

    Sorry, missed the point of your question first. You can locate any element witihin the form with xpath locators, for example. In your case

    find.Element(By.xpath("//form/*[@name='a']"))
    find.Element(By.xpath("//form/*[@name='b']"))
    find.Element(By.xpath("//form/*[@name='c']"))
    

    If you have multiple form tags on your page, you can specify it with any attribute as well.

    find.Element(By.xpath("//form[@name='something']/*[@name='c']")) //as it is in your sample
    

    Also you can specify form first, and work with elements within it. I'm not sure abut your syntax, but first, you need to return the form webelement into some var (let it be form) in any way. After that you may pass this var instead of webdriver instance.

    form.find.Element(By.xpath('./some/child/locator'))
    

提交回复
热议问题