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

后端 未结 2 1523
有刺的猬
有刺的猬 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-18 10:13

    Using the aria-label property you can try the following xpath:

    driver.find_element_by_xpath("//div[@aria-label='Any time']/div[@class='mn-hd-txt' and text()='Any time']");
    

    OR

    driver.find_element_by_xpath("//div[@aria-label='Any time']/div[@class='mn-hd-txt'][text()='Any time']");
    

    If using aria-label property is not a mandatory requirement you can use the following:

    driver.find_element_by_xpath("//div[@class='hdtb-mn-hd']/div[@class='mn-hd-txt' and text()='Any time']");
    

    OR

    driver.find_element_by_xpath("//div[@class='hdtb-mn-hd']/div[@class='mn-hd-txt'][text()='Any time']");
    

提交回复
热议问题