0

I am trying to click what seems to be a custom element on a webpage. I have tried various methods but I cannot get it to work.

The element is circled in this screenshot:

enter image description here

And can be found here. The element can be accessed by clicking one of the boxes in the grid.

Here are some of the things I have tried to access it:

driver.find_element_by_xpath("//div[@class='_2S_LCT']")

driver.find_element_by_xpath("//*[@id='ew--26832009171']")

Is the element inaccessible or is there a way of clicking on it?

2
  • What are the steps to reach to that web element ? Commented Jan 11, 2022 at 8:16
  • Hi @cruisepandey the script clicks on one of the boxes in the grid to bring it up. This example is from clicking a link under the Paddy Power header. Commented Jan 11, 2022 at 8:21

2 Answers 2

3

To get XPath of an element on website page, you can right click on the HTML element in inspector and in the menu Copy, you will be able to Copy full XPath.

Copy full XPath on Chrome

Sign up to request clarification or add additional context in comments.

Comments

-1

There are basically 4 ways to click in Selenium.

I will use this xpath

//input[@type='checkbox'][contains(@id,'ew--')]

Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.

Steps to check:

Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the xpath and see, if your desired element is getting highlighted with 1/1 matching node.

Code trial 1:

time.sleep(5)
driver.find_element_by_xpath("//input[@type='checkbox'][contains(@id,'ew--')]").click()

Code trial 2:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@type='checkbox'][contains(@id,'ew--')]"))).click()

Code trial 3:

time.sleep(5)
button = driver.find_element_by_xpath("//input[@type='checkbox'][contains(@id,'ew--')]")
driver.execute_script("arguments[0].click();", button)

Code trial 4:

time.sleep(5)
button = driver.find_element_by_xpath("//input[@type='checkbox'][contains(@id,'ew--')]")
ActionChains(driver).move_to_element(button).click().perform()

Imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

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.