from the below 3
classes with the same class name. I'm n" /> from the below 3
classes with the same class name. I'm n" /> from the below 3
classes with the same class name. I'm n"/>

How to select 1st div with same classname but different conditions using Python Selenium

325 Views Asked by At

New to Python Selenium and I want to select the 3rd:

<div class = "inner-TPBYkbxL" ...> 

from the below 3 <div> classes with the same class name. I'm not sure what is meant by

<... "data-is-fake-main-panel" =  "true" or "false"> 

after

<div class = "inner-TPBYkbxL" ...>

Snapshot:

Div Class Structure

How should I structure my selenium web driver script? I've tried the below:

driver.find_element_by_xpath("//div[@class='inner-TPBYkbxL']").click()

But it returned:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
1

There are 1 best solutions below

3
undetected Selenium On

Generally <div> elements aren't interactable barring some exceptational conditions. Hence when you invoke click() on the <div> element identified by:

driver.find_element_by_xpath("//div[@class='inner-TPBYkbxL']")

You are facing:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

This usecase

Not that super clear why you would click a <div> element. However to identify the the element:

<div class = "inner-TPBYkbxL" data-is-fake-main-panel="false"> 

you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    element = driver.find_element(By.CSS_SELECTOR, "div,inner-TPBYkbxL[data-is-fake-main-panel='false']")
    
  • Using XPATH:

    element = driver.find_element(By.XPATH, "//div[@class='inner-TPBYkbxL' and @data-is-fake-main-panel='false']")
    
  • Note : You have to add the following imports :

    from selenium.webdriver.common.by import By