0

I tried to click on those login button but fail with xpath and css.

<div id="WsopApp">
    <div id="PokerApp" class="">
        <div class="login-popup">
            <div class="login-services-container">
                <button class="btn-social btn-facebook" data-qaid="signInFacebook">
                    <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 320 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">
                        <path d="M279.14 288l14.22-92.66h-88.91v-60.13c0-25.35 12.42-50.06 52.24-50.06h40.42V6.26S260.43 0 225.36 0c-73.22 0-121.08 44.38-121.08 124.72v70.62H22.89V288h81.39v224h100.17V288z">
                        </path>
                    </svg>Sign in with Facebook
                </button>
                <button class="btn-social btn-google" data-qaid="signInGoogle">
                    <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 640 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">
                        <path d="M386.061 228.496c1.834 9.692 3.143 19.384 3.143 31.956C389.204 370.205 315.599 448 204.8 448c-106.084 0-192-85.915-192-192s85.916-192 192-192c51.864 0 95.083 18.859 128.611 50.292l-52.126 50.03c-14.145-13.621-39.028-29.599-76.485-29.599-65.484 0-118.92 54.221-118.92 121.277 0 67.056 53.436 121.277 118.92 121.277 75.961 0 104.513-54.745 108.965-82.773H204.8v-66.009h181.261zm185.406 6.437V179.2h-56.001v55.733h-55.733v56.001h55.733v55.733h56.001v-55.733H627.2v-56.001h-55.733z">
                        </path>
                    </svg>Sign in with Google
                </button>
                <button class="btn-social btn-one-connect" data-qaid="signInOneConnect">
                    <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">
                        <path d="M512 464c0 26.51-21.49 48-48 48H48c-26.51 0-48-21.49-48-48V200.724a48 48 0 0 1 18.387-37.776c24.913-19.529 45.501-35.365 164.2-121.511C199.412 29.17 232.797-.347 256 .003c23.198-.354 56.596 29.172 73.413 41.433 118.687 86.137 139.303 101.995 164.2 121.512A48 48 0 0 1 512 200.724V464zm-65.666-196.605c-2.563-3.728-7.7-4.595-11.339-1.907-22.845 16.873-55.462 40.705-105.582 77.079-16.825 12.266-50.21 41.781-73.413 41.43-23.211.344-56.559-29.143-73.413-41.43-50.114-36.37-82.734-60.204-105.582-77.079-3.639-2.688-8.776-1.821-11.339 1.907l-9.072 13.196a7.998 7.998 0 0 0 1.839 10.967c22.887 16.899 55.454 40.69 105.303 76.868 20.274 14.781 56.524 47.813 92.264 47.573 35.724.242 71.961-32.771 92.263-47.573 49.85-36.179 82.418-59.97 105.303-76.868a7.998 7.998 0 0 0 1.839-10.967l-9.071-13.196z">
                        </path>
                    </svg>Sign in with Email
                </button>
            </div>

Here my code with css

driver.find_element_by_css_selector('#PokerApp > div.login-popup > div.login-services-container > button.btn-social.btn-one-connect > svg > path').click()

And with xpath:

driver.get("https://playwsop.com/play")
time.sleep(15)
driver.find_element_by_xpath("//button[@data-qaid='signInOneConnect']")

Here is the page:

https://playwsop.com/play

Here is my error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[@data-qaid='signInOneConnect']"}   (Session info: chrome=90.0.4430.72) 
Stan Sal
  • 33
  • 1
  • 6

2 Answers2

1

The element you are after is inside an iframe you need to switch it first to access the element

Use WebDriverWait() and wait for frame available and switch.

wait=WebDriverWait(driver,60)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//div[@id='wsop-app-container']/iframe")))
wait.until(EC.element_to_be_clickable((By.XPATH,"//button[@data-qaid='signInOneConnect']"))).click()

you need to import below libraries

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
    
KunduK
  • 32,888
  • 5
  • 17
  • 41
0

The button you are looking for is inside iframe so first you have to switch into that iframe
You are using a wrong locators.
Use //button[@data-qaid='signInOneConnect'] xpath instead.
Additionally, you are talking about the https://playwsop.com/play page and not https://playwsop.com/

Prophet
  • 32,350
  • 22
  • 54
  • 79
  • Thanks for the comment, here my code and still cannot find it. ```driver.get("https://playwsop.com/play") time.sleep(15) driver.find_element_by_xpath("//button[@data-qaid='signInOneConnect']")``` and still get this error ```selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[@data-qaid='signInOneConnect']"} (Session info: chrome=90.0.4430.72)``` – Stan Sal Apr 15 '21 at 18:13
  • Sure. Because first you should land on `https://playwsop.com/`, then press the "Play Now" button. But there is no "Login" button on the Home page at all and no element located by the css or xpath you providd initially – Prophet Apr 15 '21 at 18:18
  • Thanks, I knew, I edited my code and get directly to the https://playwsop.com/play. But still cannot. Were you able to click? – Stan Sal Apr 15 '21 at 18:21
  • I will not open a project to debug this issue, however I see the buttons there. Which one you wanted to use? After the page is loaded try using waitForElementToBeVisible instead of clickability. – Prophet Apr 15 '21 at 18:27
  • The last button, I used python here my new code and same error: ```WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//button[@data-qaid='signInOneConnect']"))).click()``` – Stan Sal Apr 15 '21 at 18:33
  • 1
    I see it is inside the iframe. Try switching to the iframe first and then find the element. https://stackoverflow.com/questions/7534622/select-iframe-using-python-selenium – Prophet Apr 15 '21 at 18:59