0

I need help to click a specific Image on a Website. Its in an iFrame too.

The HTML:

<i class="icon-willi-vote fxf-do-multivote" data-mv-id="1622095851001a" data-mission-id="97d05b44d86fb83b">

Snapshot of HTML:

HTML Code

Snapshot of the iframe: iFrame

How can I use this button/image with selenium and can I do it with

driver.find_element(...)

I tried find_element by xpath, class and id, but i cant find the way to get.

1
  • Please provide enough code so others can better understand or reproduce the problem. Commented Jun 7, 2023 at 17:52

2 Answers 2

0

Given the HTML:

<i class="icon-willi-vote fxf-do-multivote" data-mv-id="1622095851001a" data-mission-id="97d05b44d86fb83b">

To click() on the element you can use either of the following locator strategies:

  • Using css_selector:

    driver.find_element(By.CSS_SELECTOR, "i.icon-willi-vote.fxf-do-multivote[data-mv-id][data-mission-id]").click()
    
  • Using xpath:

    driver.find_element(By.XPATH, "//i[@class='icon-willi-vote fxf-do-multivote'][@data-mv-id and @data-mission-id]").click()
    

Ideally to click on the clickable element 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, "i.icon-willi-vote.fxf-do-multivote[data-mv-id][data-mission-id]"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//i[@class='icon-willi-vote fxf-do-multivote'][@data-mv-id and @data-mission-id]"))).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
    

Update

The desired element is within an <iframe> and if the values within the attributes data-mv-id="1622095851001a" and data-mission-id="97d05b44d86fb83b" remains constant throughout you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src^='https://www.willi.aka.krone.at']")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "i.icon-willi-vote.fxf-do-multivote[data-mv-id='1622095851001a'][data-mission-id='97d05b44d86fb83b']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[starts-with(@src, 'https://www.willi.aka.krone.at')]")))    
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//i[@class='icon-willi-vote fxf-do-multivote'][@data-mv-id='1622095851001a' and @data-mission-id='97d05b44d86fb83b']"))).click()
    

Reference

You can find a couple of relevant discussions in:

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

6 Comments

Thx, but there are several ".icon-willi-vote.fxf-do-multivote" Buttons on the Homepage, i need a way to include the specific Button/Icon with: data-mv-id="1622095851001a" data-mission-id="97d05b44d86fb83b" Especially the Numbers, so the Program does not click the wrong Button. Thats the only way to get the specific Button. I can send u the whole Website, if u want
@DanielR The values within data-mv-id="1622095851001a" and data-mission-id="97d05b44d86fb83b" are dynamically generated. So we need to uniquely identify them relating to it's ancestors. Update the question with then text based HTML including the ancestor elements.
As i know, these 2 Data Values stayed the same all day long an in every Browser i tested, there is no other way to uniquely identify the button in the backend. here is the website: krone.at/3024904
I think the problem is a iframe, the button/image is in an iframe. I uploaded a Image of the iFrame.
@DanielR Yes, you are correct, I presumed you already taken care of the iframe early in your code. Checkout the answer update and let me know the status.
|
0

You can try finding the element with css selector and class names:

element = driver.find_element(By.CSS_SELECTOR, ".icon-willi-vote.fxf-do-multivote")

If the element is found successfully you can then .click() on the element or perform other operations.

1 Comment

There are more .icon-willi-vote.fxf-do-multivote Buttons on the Homepage, i need a way to include the specific Button/Icon with: data-mv-id="1622095851001a" data-mission-id="97d05b44d86fb83b"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.