Q: Unable to locate Xpath Element Hi I am fairly new to selenium .Can somebody please suggest on how to locate and element inside iframe asi am getting error below.
I am trying to implement an Automation Script on Salesforce Pardot page and there are 2 iframes and i want to access Button on 1st iframe Tag and click on same. 

Error:- selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:
  {"method":"xpath","selector":"//*[starts-with(@class,'slds-button_reset')]"}
  (Session info: chrome=80.0.3987.122)

Screenshot for DOM Button Element
Screenshot for DOM Button Element along with Iframe tag
Code Written Previously 
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
prefs = {'download.default_directory': r'C:\Pardot'}
chrome_options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(executable_path="D:\XXX XXXX\XXXX\drivers\chromedriver.exe", options=chrome_options)
driver.get('https://pi.pardot.com/engagementStudio/studio#/15627/reporting')
user_name = driver.find_element_by_css_selector('#email_address')
user_name.send_keys('XXXXXXXXXXXXXXXXXXX')
password = driver.find_element_by_css_selector('#password')
password.send_keys('XXXXXXXXXXXXXXXXX)
submit_button = driver.find_element_by_css_selector('input.btn')
submit_button.click()
iframe_list =  driver.find_elements_by_tag_name("iframe")
driver.switch_to.frame(iframe_list[0])
driver.find_element_by_xpath("//*[starts-with(@class,'slds-button_reset')]")
driver.close()


A: As the the desired element is within an <iframe> so to invoke click() on the element you have to:


*

*Induce WebDriverWait for the desired frame_to_be_available_and_switch_to_it().

*Induce WebDriverWait for the desired element_to_be_clickable().

*You can use either of the following  Locator Strategies:


*

*Using CSS_SELECTOR:
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#content-frame")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[data-qa='reporting-filter-trigger-toggle'][data-ember-action]"))).click()


*Using XPATH:
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='content-frame']")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@data-qa='reporting-filter-trigger-toggle' and @data-ember-action]"))).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


Reference
You can find a couple of relevant discussions in:


*

*Selenium "selenium.common.exceptions.NoSuchElementException" when using Chrome

*Ways to deal with #document under iframe

A: Try this :
//li[@id='ember943']

A: You need to get iframe tag first and switch driver to it like following.
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
assuming that driver is a healthy instance of webdriver. To continue with the default content do 
driver.switch_to.default_content()
Please refer this link

A: I hope that you're switching to the correct Iframe to fetch the element... Please see the example below
driver.switchTo().frame("content-frame")
driver.findElement(By.xpath("//div[@id='ember740']/div[2]/div/ol/li/div/button")
driver.switchTo().defaultContent()

