ErrorX
ErrorX

Reputation: 39

Python Selenium1

Hey im new to python selenium developing, and i kinda need some help if any one have some extra time:)

Im using this site: https://www.youlikehits.com/retweets.php Im trying to click on confirm button the green one. But for some reson i cant figure out how to click it. Every try it says that it cant locate it.

Do you guys have any ide?

Screen: https://i.sstatic.net/Z31In.png Screen of html code: https://i.sstatic.net/herDB.png

Code:

driver.find_element_by_link_text('Confirm').click()


try:
        print("Trying")
        print("Making points Click")
        time.sleep(5)
except NoSuchAttributeException:
        print("Element not found!")
        continue
except:
        print("Something els is wrong!")

driver.quit()

Best Regards Felix

Upvotes: 0

Views: 54

Answers (1)

KunduK
KunduK

Reputation: 33384

The Confirm link is inside an iframe and you need to switch to iframe first inorder to access the element.

Use WebDriverWait() wait for frame_to_be_available_and_switch_to_it() and follwoing css selector Use WebDriverWait() wait for element_to_be_clickable() and follwoing xpath

driver.get("url")
wait=WebDriverWait(driver,10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[src^='retweetrender.php']")))
wait.until(EC.element_to_be_clickable((By.XPATH,"//a[contains(.,'Confirm')]"))).click()

OR

driver.get("url")
wait=WebDriverWait(driver,10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[src^='retweetrender.php']")))
wait.until(EC.element_to_be_clickable((By.LINK_TEXT,"Confirm"))).click()

You need following imports.

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

Upvotes: 1

Related Questions