-1

im trying to find the parent class name on a element, but i don't know how i find it.

Here is a picture of what im trying to find the parent class name of.

What do i need to press to find the parent class name?

I can send the link to the website and show which element I am trying to get parent class name on

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Your code trials? – undetected Selenium Jan 03 '22 at 07:59
  • I have not tried anything yet, because i don't know how i will do it. – Robert Tacchini Jan 03 '22 at 08:28
  • 2
    Please read why a [screenshot of HTML or code or error is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Consider updating the Question with formatted text based relevant HTML, code trials and error stack trace. – undetected Selenium Jan 03 '22 at 08:28
  • As mentioned by @DebanjanB, please share a link to that page or the HTML **code**, not a picture of all that page or at least as large as possible block of HTML block containing that specific element – Prophet Jan 03 '22 at 08:32
  • I haved updatet the post. I hope that enough – Robert Tacchini Jan 03 '22 at 08:36
  • I see no "Videre til kassen" text on that page – Prophet Jan 03 '22 at 08:38
  • Please don't change the question based on which you have received well researched answers. Once you receive canonical answers changing the question can make all the existing answers invalid and may not be useful to future readers. If your requirement have changed feel free to raise a new question. StackOverflow contributors will be happy to help you out. For the time being I have reverted back the question to it's initial state. – undetected Selenium Jan 06 '22 at 15:16

1 Answers1

0

To find the parent classname of the WebElement you need to induce WebDriverWait for the visibility_of_element_located() and you can use the following Locator Strategy:

  • Code Block:

    driver.get("https://www.zalando.dk/cart")
    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[text()='Fortsæt med at shoppe']//parent::button[1]"))).get_attribute("class"))
    
  • Console Output:

    z-1-button z-coast-base-primary-accessible undefined z-1-button--primary z-1-button--button
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352