Python Selenium cannot locate button within an iframe

click here for imageI am trying to interact with the "바카라 멀티플레이" button located at the center of the website. Even after switching into an iframe, I am unable to detect the button. How can I achieve this?

from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common import exceptions
import sys
import asyncio

"""
    Chromedriver Options / Driver setting
"""
options = webdriver.ChromeOptions()
#ptions.add_argument('headless')
options.add_argument('window-size=1920,1080')
options.add_argument("disable-gpu")

driver = webdriver.Chrome(executable_path='C:/chromedriver/chromedriver.exe', chrome_options=options)

driver.get('https://ggl-maxim.com/')

driver.find_element_by_xpath('//*[@id="body"]/div/div[2]/div/div[2]/fieldset/input[1]').send_keys('tnrud3080')
driver.find_element_by_xpath('//*[@id="body"]/div/div[2]/div/div[2]/fieldset/input[2]').send_keys('tnrud3080')
driver.find_element_by_xpath('//*[@id="body"]/div/div[2]/div/div[2]/fieldset/button[1]').click()

time.sleep(2)
driver.get('https://ggl-maxim.com/api/popup/popup_menu.asp?mobile=0&lobby=EVOLUTION')
wait = WebDriverWait(driver, 20)
wait.until(EC.frame_to_be_available_and_switch_to_it("gameIframe"))
driver.find_element_by_class_name(".wrapper--1zUtU").click()
wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".svg--1nrnH")))

Answer №1

This .svg--1nrnH doesn't show the button you should be clicking on. Also, keep in mind that this is an SVG element, so you can't simply use a CSS selector to find it.

Code :

driver = webdriver.Chrome("C:\\Users\\***\\**\\Desktop\\Selenium+Python\\chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 30)
driver.get('https://ggl-maxim.com/')

driver.find_element_by_xpath('//*[@id="body"]/div/div[2]/div/div[2]/fieldset/input[1]').send_keys('tnrud3080')
driver.find_element_by_xpath('//*[@id="body"]/div/div[2]/div/div[2]/fieldset/input[2]').send_keys('tnrud3080')
driver.find_element_by_xpath('//*[@id="body"]/div/div[2]/div/div[2]/fieldset/button[1]').click()
sleep(5)
driver.get('https://ggl-maxim.com/api/popup/popup_menu.asp?mobile=0&lobby=EVOLUTION')
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID,"gameIframe")))
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".wrapper--1zUtU")))
sleep(5)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".wrapper--1zUtU button"))).click()
sleep(5)
print("Operation successful")

O/P :

https://i.stack.imgur.com/xIZIJ.jpg

Answer №2

When implementing the login action, it is recommended to utilize the following xpaths for a cleaner code:

driver.get('https://ggl-maxim.com/')

driver.find_element_by_xpath("//input[@placeholder='아이디']").send_keys('tnrud3080')
driver.find_element_by_xpath("//input[@placeholder='비밀번호']").send_keys('tnrud3080')
driver.find_element_by_xpath("//button[@class='btn_apply']").click()

If you encounter issues with clicking the 바카라 멀티플레이 button, try using the xpath below:

driver.find_element_by_xpath("//div[@class='wrapper--1zUtU']").click()

Answer №3

Once you press the button to retrieve the list of games, you must navigate to a different iframe. There are two iframes with very similar names, so I have used a selector that specifies an iframe name starting with

https://evo.kplaycasino.com/frontend/evo/r2/#category"]
.

from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common import exceptions
import sys
import asyncio

"""
    Chromedriver Options / Driver setting
"""
options = webdriver.ChromeOptions()
#ptions.add_argument('headless')
options.add_argument('window-size=1920,1080')
options.add_argument("disable-gpu")

driver = webdriver.Chrome(executable_path='/snap/bin/chromium.chromedriver', chrome_options=options)

driver.get('https://ggl-maxim.com/')

driver.find_element_by_xpath("//input[@type='text']").send_keys('tnrud3080')
driver.find_element_by_xpath("//input[@type='password']").send_keys('tnrud3080')
driver.find_element_by_css_selector('.btn_apply').click()

time.sleep(2)
driver.get('https://ggl-maxim.com/api/popup/popup_menu.asp?mobile=0&lobby=EVOLUTION')
wait = WebDriverWait(driver, 20)
wait.until(EC.frame_to_be_available_and_switch_to_it("gameIframe"))
wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".svg--1nrnH")))
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".wrapper--1zUtU button>span")))
driver.find_element_by_css_selector(".wrapper--1zUtU button").click()
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'iframe[src^="https://evo.kplaycasino.com/frontend/evo/r2/#category"]')))
iframe2 = driver.find_element_by_css_selector('iframe[src^="https://evo.kplaycasino.com/frontend/evo/r2/#category"]')
driver.switch_to.frame(iframe2)
wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".svg--1nrnH")))

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Selenium's SendKeys function fails to execute when the computer is locked

When filling a date in a text box using Python 3.9.5 and Selenium 4.1.0 with Microsoft Edge 98.0.1108.43 on Windows 10, I utilize the following code: #element is the web element I want to fill element = "element_name" date = driver.find_element(B ...

Utilizing distinct useState for mapped elements

I am struggling to find a solution on how to pass specific useState states to respective mapped elements. export const Polska = () => { const [riverVisible, setRiverVisible] = useState(false) const [mountainVisible, setMountainVisible] = useState(fa ...

Is it possible to iterate through div elements using .each while incorporating .append within an AJAX call?

After sending AJAX requests and receiving HTML with multiple div elements (.card), I am using .append to add new .card elements after each request, creating an infinite scroll effect. However, I am facing issues when trying to use .each to iterate over all ...

What is the process for adjusting the color of a particular date in the <input type=Date> field?

Is there a way to modify the styling, such as color, of the input type date in HTML 5? In HTML 5, we can display a calendar using <input type=date>. For example, if March 23rd is a holiday and I want to highlight this specific date in red, how can I ...

Ways to extract the content from a div when there are numerous divs sharing the same class identifier

Attempting to determine the number of chapters in a manga using BeautifulSoup, but struggling due to confusing containment: [Here is a visual representation of the issue]https://gyazo.com/c45fef82b0ce52dacd99d213538ab570) Only interested in extracting th ...

Unable to apply the flex-grow property to a column flex box that has a specified minimum height

I am currently working on designing a website layout that harnesses the power of flexbox to fill the entire page with content, even when the content does not fully occupy the length of the page. My approach involves creating a large flexbox container with ...

Choose a class and all its offspring as a selector

I possess the subsequent <label class="noblock"> <input> ... ... </label> Is there a method to indicate the CSS property display: inline for both the class noblock and its offspring (all elements within it)? ...

django ajax request returning a 403 error

While attempting to compile project https://github.com/kannan4k/django-carpool, I encountered an error during an ajax call. The error message displayed was: "Failed to load resource: the server responded with a status of 400 (BAD REQUEST)." I suspect that ...

Creating a canvas that adjusts proportionally to different screen sizes

Currently, I am developing a pong game using Angular for the frontend, and the game is displayed inside an HTML canvas. Check out the HTML code below: <div style="height: 70%; width: 70%;" align="center"> <canvas id=&q ...

Using PHP Hover should apply CSS styles exclusively to the specified element

I have a piece of PHP code that displays cards. What I need: When a user hovers over the entire element, I want to make the title bolder, move the arrow to the left, and zoom in on the image of that particular hovered element. <div class="posti-class ...

converting web job json data into a pandas dataframe

Currently, I am endeavoring to retrieve JSON data for logs from Azure WebJobs services using the REST API. While I have managed to extract the data into a dataframe with various columns, my goal is to format the "lastrun" column in a tabular layout, where ...

Is there a way to adjust the opacity of a background image within a div?

I have a lineup of elements which I showcase in a grid format, here's how it appears: https://i.stack.imgur.com/JLCei.png Each element represents a part. The small pictures are essentially background-images that I dynamically set within my html. Up ...

Set border-image to have rounded corners

I am attempting to create a circular button with a unique border effect. Here is the code I have implemented so far: body { display: flex; height: 100vh; overflow: hidden; justify-content: center; align-items: center; } button { height: 80px ...

Is there a way to obtain metadata for a specific link?

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title><$BlogPageTitle$></title> <meta property="og:title" content=" ...

Unable to choose the div element with id ":1"

Just starting out with web development, and I have a div element with the following attributes: <div class="" id=":1" role="treeitem" aria-selected="false" aria-expanded="false" aria-level="1" aria-labelledby=":1.label" aria-setsize="10" aria-posinset= ...

Custom styles for PrimeNG data tables

Struggling to style the header of a datatable in my Angular project using PrimeNG components. Despite trying various solutions, I am unable to override the existing styles. Even attempting to implement the solution from this PrimeNG CSS styling question o ...

How can you give a block a unique name using a variable in Jinja2?

In the template "base.html" that I have, there is a set of ids called list_of_ids. The template contains a for loop that goes through each id in this list and outputs a specific block of content for each one. {% set list_of_ids = ['id1', 'i ...

Discover your screen orientation using Python

I recently developed a Python game using Pygame which operates flawlessly in both Portrait and Landscape orientations. However, I encountered an issue when the user rotates their device while the game is running, causing everything to appear jumbled up on ...

Mastering the art of list comprehension in Python: avoiding the common pitfall of getting stuck with a list of booleans

My goal is to eliminate periods, commas, single and double quotes from the end of each string within a list. Each string is part of a larger list of strings. string_list= ["cars." , "red" , "orange," , "man'" , "thus:"] desired_output --->["cars" ...

Display the website logo when users share on WhatsApp

My goal is to have my website icon appear in WhatsApp when I share it (similar to the example below). https://i.stack.imgur.com/KCWi8.jpg I initially tried using this code, but it didn't work: <link rel="shortcut icon" href="css/img/favicon/favi ...