Reputation: 23
enter image description hereI want to click the button called "바카라 멀티플레이" which locates center of the site. I switched into iframe, however it seems to be not detecting the button. How can I?
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")))
Upvotes: 2
Views: 148
Reputation: 4212
After you click that button to get the games list you need to switch to another iframe. There are two iframes with a very similar names, so I used selector which indicates that iframe name starts 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")))
Upvotes: 0
Reputation: 29362
This .svg--1nrnH
does not represent the button you wanna click.
Plus that is a svg element you cannot use just the that css selector to locate the element.
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 :
Upvotes: 1
Reputation: 969
For the login action use the below xpaths. This way your code will look neat.
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()
For the click of button 바카라 멀티플레이, try using the below xpath and see if it works:
driver.find_element_by_xpath("//div[@class='wrapper--1zUtU']").click()
Upvotes: 0