0

I have this webpage (https://goldapple.ru/) on which I want to parse some data about cosmetics. However, when I open the webpage, the popup button appears, and I want to click the left "Да, верно". Unfortunately, the TimeoutException(message, screen, stacktrace) error appears, so the problem is that the machine doesn't see the button.

The webpage HTML code:

<button type="button" class="MMwlC KQN8E yVRvi I1E8J PrKjg Rt0VH"><span class="_1MvHE"><span class="nOERC">
      Да, верно
    </span> <span class="SdR9G" style="display: none;"><div class="o8w4X"><div class="-tctp"></div> <div class="-tctp"></div> <div class="-tctp"></div> <!----></div></span></span></button>

My code's like that:


#import some dependencies
from selenium.webdriver import Chrome
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from time import sleep
#actual code
browser = Chrome()
url = "https://goldapple.ru/"

browser.get(url)

wait = WebDriverWait(browser, 10)

wait.until(
    EC.element_to_be_clickable((By.XPATH, "//*[@id='__layout']/div/div[5]/div[2]/div[1]/div/div[2]/button[1]"))
).click()

Some facts you need to know imho:


  1. I used the WebDriverWait to get some time for a popup button to appear
  2. I used the element_to_be_clickable condition
  3. XPATH was used as a reference to the button, so there should be no problem with the address
  4. There's no shadow root on a webpage

P.S. Some motivation: If someone solves the problem, it would be considered (at least by me) as the Selenium breakthrough

2
  • How did you get that xpath? Did you type it by hand? Or did you inspect the button element in your browser and copy the xpath exactly? Commented Jun 30, 2024 at 16:37
  • Just click it with javascript. There are plenty examples on SO how to do it. Commented Jun 30, 2024 at 16:54

1 Answer 1

0
//*[@id='__layout']/div/div[5]/div[2]/div[1]/div/div[2]/button[1]

Above XPath expression is incorrect. It does not locate any element. Use below XPath expression instead.

//span[contains(text(),'Да, верно')]

Code:

wait.until(EC.element_to_be_clickable((By.XPATH, "//span[contains(text(),'Да, верно')]"))).click()
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you really much, it worked! Could you please tell why my XPath didn't work? I mean I copied it directly, I didn't write it by myself, so no mistale here
That XPath is incorrect. It is not locating any elements. Check this answer link point 1. to understand how you can test if the XPath is locating any elements or not. I suggest writing your own relative XPaths. Google and learn about writing custom XPath, there are plenty of material on internet. What should I do when someone answers my question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.