pythonseleniumselenium-webdriverautomation

Find element by value Selenium/Python


I am using Selenium with Python to automaticlly extract some data from our power plants and right now I need to click on an element. The problem is that the element's xpaths and order change for each plant we are monitoring. The only static info is the value, just like in the 3rd line value="T_U0.

I tried many approaches and I couldn't find a solution. I can't use index or child because the order of the parameters is changing. I tried CSS selector with no success.

Here you get some of my tries...

driver.find_element_by_xpath("//input[@value='T_U0']").click()
driver.find_element_by_css_selector("input[@data-id-sys-abbreviation='388']").click()

I tried many other things but I was just desperately trying anything.

What I really need is a find_by_value, if there is a way of doing it please let me know, if there isn't please show me how I can do it.

I need to click in some options that change order accordingly to the plant


Solution

  • The problem is with the first xpath. You are trying to locate an input while you need to get option.

    Try this:

    driver.find_element_by_xpath("//option[@value='T_U0']").click()