Using aria-label to locate and click an element with Python3 and Selenium

后端 未结 2 1520
有刺的猬
有刺的猬 2021-01-18 09:49

I want to click or more respectively, expand the \"Any time\" button. I\'ve tried to locate the element by class_name and xpath. The problem is that the class and xpath are

2条回答
  •  孤街浪徒
    2021-01-18 10:06

    So, I was just wrestling with this for the last couple days, and it was proving to be a huge headache. The aria-label was basically the only reliable attribute, and the xpath solution was not working for me.

    On a whim, I tried using:

    driver.find_elements_by_css_selector("[aria-label=XXXX]")
    

    where XXXX was the aria labels that I was searching for. Worked like a charm.

    All this to say, try using the css selector. It just works.

提交回复
热议问题