1

I tried with XPath but selenium can't click this image/button.

enter image description here

from undetected_chromedriver.v2 import Chrome

def test():

    driver = Chrome()
        
    driver.get('https://bandit.camp')
    WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,"/html/body/div[1]/div/main/div/div/div/div/div[5]/div/div[2]/div/div[3]/div"))).click()
if __name__ == "__main__":

    test()
3
  • Post the URL and code you've tried. Commented Nov 25, 2022 at 17:01
  • Which tag do you need to click? in that tag, which attribute value keeps on changing? Your question is not clear. Edit the question, and add more and a clear explanation. Commented Nov 25, 2022 at 17:37
  • I edited, can u look this? Commented Nov 26, 2022 at 6:06

2 Answers 2

1

Try the below one, I checked it, and it is working fine, while clicking on the link it is opening a separate window for login.

free_case = driver.find_element(By.XPATH, ".//p[contains(text(),'Open your free')]")

driver.execute_script("arguments[0].scrollIntoView(true)", free_case)
time.sleep(1)
driver.execute_script("arguments[0].click();", free_case)
Sign up to request clarification or add additional context in comments.

2 Comments

I got a error. Message: element click intercepted: Element <p data-v-e4610dc2="" class="mb-0">...</p> is not clickable at point (285, 914). Other element would receive the click: <div data-v-0d84310b="" class="d-flex align-center px-4 mb-2">...</div>
Updated the code, check it.
1

First you need to wait for presence of that element.
Then you need to scroll the page down to make that element visible since initially this element is out of the visible screen so you can't click it.
Now you can click it and it works.
The code below is working:

import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")
options.add_argument('--disable-notifications')

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 10)

url = "https://bandit.camp/"
driver.get(url)

element = wait.until(EC.presence_of_element_located((By.XPATH, "//div[contains(.,'daily case')][contains(@class,'v-responsive__content')]")))
element.location_once_scrolled_into_view
time.sleep(0.3)
element.click()

Comments

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.