1

I am learning Selenium and trying to click the GO button: https://speedtest.telstra.com/

<button class="button background-primary-hover text-primary" aria-label="start your speedtest">
<span style="font-size: unset; overflow-wrap: unset;">GO</span></button>

What are all possible Selenium methods to get that button clicked, elem = driver.find_element_by_....???

I also would like to see what I found, so should print(elem.text) then be used?

0

3 Answers 3

2

As per the website https://speedtest.telstra.com/ the desired element is within an <iframe> so you need to induce WebDriverWait to switch to the <iframe> and then look out for the element and you can use the following solution:

  • Using XPATH:

    WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='speed-test' and @src='//telstra-nbn.speedtestcustom.com']")))
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='button background-primary-hover text-primary']/span[contains(.,'GO')]"))).click()
    
  • Using CSS_SELECTOR:

    WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"//iframe.speed-test[src*='speedtestcustom']")))
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.button.background-primary-hover.text-primary[aria-label='start your speedtest']>span"))).click()
    

Note : You have to add the following imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Sign up to request clarification or add additional context in comments.

4 Comments

I have been researching for this very solution for 2 hours. I wish I could found it, but thanks for brightening me up. I did not know WebDriverWait this efficient. I learned a lot from this answer. Thanks.
Thanks, so locating the clickable by XPATH. How would I do it using Class name or CSS selectors?
@user3013157 Checkout my updated answer and let me know the status.
@New contributor, oh thanks so much, I understand it now :)
0

You have to use xpath, there is xpath helper tool for chrome. You can install it.

button = driver.find_element_by_xpath("your xpath")

button.click()

1 Comment

There is no option to click by xpath in a frame.
-1

Try this:

browser.find_element_by_class_name("button background-primary-hover text-primary").click()

Since it will select the element and click it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.