0

enter image description here

I can't seem to find the right path for the button marked above. Any help on how to simulate a click on this button?

This is the website, and linked under is a greater part of the source code.

enter image description here

enter image description here

  • 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 Aug 19 '20 at 19:34

2 Answers2

0

To click on the element with text as Lukk you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "ytcp-button#close-button div[label='Lukk']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//ytcp-button[@id='close-button']//div[@label='Lukk' and text()='Lukk']"))).click()
    
  • 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
0

I would say to first wait for the popup to open. Explicit wait can do:

Here is a sample code: https://seleniumbyexamples.github.io/waitvisibility

Your selector would be paper-dialog#dialog

Once the popup is visible you can now wait for the button.

You can use wait to be clickable:

https://seleniumbyexamples.github.io/waitclickable

The id would be close-button

You can also try other locators:

https://seleniumbyexamples.github.io/locator

  • Thanks for the attempt to help, but unfortunately it didn't work. For some reason, it struggles to find the element I'm looking for, and I've got no clue as to why that is. – Anders Haarberg Eriksen Aug 20 '20 at 15:39
  • It might that element you are waiting for did not load. If you are doing headless then you can just take a screenshot of the current page before accessing the element. driver.save_screenshot("screenshot.png") – slackingslacker Aug 21 '20 at 09:16