1

How to automate webpage button control like having span child by using

driver. findElement_by_xpath ()

on Ubuntu Linux and chromium Autotest

The wesite is: https://www.youtube.com/my_webcam?privacy=public

I would like to click on Start recording button. HTML source is:

<button class="yt-uix-button yt-uix-button-size-default yt-uix-button-dark yt-uix-button-has-icon webcam-record-button" type="button" onclick=";return false;" id="record-button">
<span class="yt-uix-button-icon-wrapper">
<span class="yt-uix-button-icon yt-uix-button-icon-upload yt-sprite">
</span>
</span>
<span class="yt-uix-button-content">Start recording </span>
</button>  

We have tried it by using

driver.find_element_by_css_selector() 
driver.find_element_by_id()
driver.find_element_by_xpath ()

However, nothing has worked. Could you please suggest us appropriate solution?

3
  • What selectors have you tried? What errors or exceptions have occurred? Commented Feb 17, 2015 at 16:34
  • Thank you for reply . Tried selectors like : #elm = driver.find_element_by_css_selector('#record-button').click() #elm = driver.find_element_by_css_selector('span.yt-uix-button-content').click() #elm = driver.find_element_by_class_name('yt-uix-button yt-uix-button-size-default yt-uix-button-dark yt-uix-button-has-icon webcam-record-button').click() elm = driver.find_element_by_class_name('webcam-record-state').click() Commented Feb 17, 2015 at 16:49
  • #elm = driver.find_element_by_css_selector('button#record-button.yt-uix-button.yt-uix-button-size-default.yt-uix-button-dark.yt-uix-button-has-icon.webcam-record-button').click() #record_xpath = '//*[@id="record-button"]/span[1]/span' #record_xpath = '//*[@id="record-button"]/span[2]' #elm = driver.find_element_by_xpath(record_xpath).click() #elm = driver.find_element_by_id('record-button').click() Exceptions have occurred: NoSuchElementException Message: u'no such element\n Commented Feb 17, 2015 at 16:49

1 Answer 1

2

The record button is within an iframe, you'll need to switch that iframe first and then locate the button with your chosen selector.

iframe = self.driver.find_element_by_css_selector("#webcam-container")
self.driver.switch_to_frame(iframe)
record = self.driver.find_element_by_css_selector("#record-button > span.yt-uix-button-content")
record.click()
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you Mark. But seems that Chrome driver python does not support .switchTo() so its throwing exception as "driver.switchTo().frame(iframe) AttributeError: 'WebDriver' object has no attribute 'switchTo' " Could you please suggest any appropriate solution.
I just realised I used the Java method, rather than the python switch_to_frame(), edited answer.
Thank you for you suggestion. It has worked with slitly changes. as sugested by Mark Rowlands like self.driver.switch_to_frame(Frame1)

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.