1

I want to access a button inside a 'div' tag but the problem is, there are two 'div' tags with same class name and one of them has the button. So how to identify which one has the button and access it. So far I tried to solve but I always get 'Unable to locate element' for button.

One is:

div class="weEq5" style="will-change; width;"

Another one is:

div class="weEq5"
    button class="_35EW6"
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Edwin
  • 11
  • 1
  • 3

2 Answers2

1

To find div contain button, first you need to select the button then go to parent element which is div

driver.find_elements_by_xpath('//button/parent::div[@class="weEq5"]')
# or
driver.find_elements_by_xpath('//button[@class="_35EW6"]/parent::div[@class="weEq5"]')
ewwink
  • 18,382
  • 2
  • 44
  • 54
0

To access the button inside the <div> you can use either of the Locator Strategies:

  • Using CSS_SELECTOR:

    myElement = driver.findElement(By.cssSelector("div[class]:not(style)>button"))
    
  • Using XPATH:

    myElement = driver.find_element_by_xpath("//div[@class and not (@style)]/button")
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352