I am finding it difficult to switch to iframe and click on O/U on this page. I need help with this guys! Here is my code below;
from random import *
import random
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import Select
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.options import Options
driver.get("https://www.sportybet.com/ke/sporty-instant-virtuals/")
driver.maximize_window()
instantplay= driver.find_element(By.XPATH, "//span[text()='Instant Virtuals']")
instantplay.click()
# find the frame
frame2 = driver.find_element(By.XPATH, "//iframe[@id='instantwin-sport']")
time.sleep(3)
driver.switch_to.frame(frame2)
time.sleep(3)
# Click O/U
driver.find_element(By.XPATH, "//li[text()[normalize-space()='O/U']]")
driver.quit()
CodePudding user response:
You never click on the element. Add .click() after finding the element.
You can also remove the sleep before the iframe and put an implicit wait to wait on the O/U button
driver.get("https://www.sportybet.com/ke/sporty-instant-virtuals/")
driver.maximize_window()
instantplay= driver.find_element(By.XPATH, "//span[text()='Instant Virtuals']")
instantplay.click()
# find the frame
frame2 = driver.find_element(By.XPATH, "//iframe[@id='instantwin-sport']")
driver.switch_to.frame(frame2)
# Click O/U
driver.implicitly_wait(10)
driver.find_element(By.XPATH, "//li[text()[normalize-space()='O/U']]").click()