kaliiiiiiiiii / Selenium-Driverless

undetected Selenium without usage of chromedriver
https://kaliiiiiiiiii.github.io/Selenium-Driverless/
Other
430 stars 52 forks source link

switch to iframe error #25

Closed guilhermepontual closed 11 months ago

guilhermepontual commented 11 months ago

**You might use driver.switch_to.target(driver.targets[0].target_id)** Error

code:

import time
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium_profiles.webdriver import Chrome
from selenium.webdriver.common.keys import Keys
from selenium_profiles.profiles import profiles
from selenium_driverless.webdriver import ChromeOptions

    def Bet365RPA(self):
        profile = profiles.Windows()
        options = ChromeOptions()
        self.driver = Chrome(profile=profile, options=options, driverless_options=True)

        url = 'https://www.bet365.com/#/HO/'
        self.driver.get(url)
        time.sleep(10)
        wait = WebDriverWait(self.driver, 10)

        target_id = wait.until(
            EC.presence_of_element_located((By.XPATH, '//div[@class="hm-MainHeaderRHSLoggedOutWide_Join "]')))
        print(target_id)
        target_id.click()

        nome, sobrenome, cpf, dia, mes, ano = self.dados_gerais()
        time.sleep(5)

        ## here
        iframe = self.driver.find_elements(By.ID, "MembersIframe")[-1]

        self.driver.switch_to.frame(iframe)

        first_name = wait.until(EC.presence_of_element_located((By.ID, 'first_name')))
        print(first_name)

if __name__ == '__main__':
    bot = Bet365()
    bot.Bet365RPA()
kaliiiiiiiiii commented 11 months ago

dublicate to https://github.com/kaliiiiiiiiii/Selenium-Driverless/issues/8

guilhermepontual commented 11 months ago

I did it the way you implemented it, but I couldn't find the iframe to manipulate the page.