Not able to find an element in iframe using Xpath and Selenium

Ravneet Kaur

I am trying to inspect an element in Iframe I am able to succesfully get into iframe but when trying to inspect element -Exception comes element not intertracble Below is the html part and the search button I am trying to click enter image description here

I tried xpath and inspection like following

//driver.findElement(By.className("gsc-search-button-v2")).click();
        //driver.findElement(By.cssSelector("button.gsc-search-button")).click();
        //driver.findElement(By.xpath("//button[text()='gsc-search-button']")).click();

        //driver.findElement(By.cssSelector("button[class='gsc-search-button gsc-search-button-v2']")).click();
//driver.findElement(By.cssSelector(".gsc-search-button.gsc-search-button-v2")).click();

//driver.findElement(By.xpath("//button[contains(@class, 'gsc-search-button gsc-search-button-v2")).click();
//wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".gsc-search-button.gsc-search-button-v2"))).sendKeys(Keys.ENTER);

Also by giving waits also like
WebDriverWait wait = new WebDriverWait(driver, 30);
    //wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".gsc-search-button.gsc-search-button-v2"))).sendKeys(Keys.ENTER);

html code enter image description here

DebanjanB

To click() on the element to search, as the the desired element is within a <iframe> so you have to:

  • Induce WebDriverWait for the desired frameToBeAvailableAndSwitchToIt.
  • Induce WebDriverWait for the desired elementToBeClickable.
  • You can use either of the following Locator Strategies:
    • Using cssSelector:

      new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe_cssSelector")));
      new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("td.gsc-search-button > button.gsc-search-button.gsc-search-button-v2"))).click();
      
    • Using xpath:

      new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("iframe_xpath")));
      new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//td[@class='gsc-search-button']/button[@class='gsc-search-button gsc-search-button-v2']"))).click();
      

Reference

You can find a couple of relevant discussions in:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Not able to find element by partial link text using Java and Selenium

Find an element using xpath

Find Xpath for element in Selenium Java

Selenium Find Element by xpath using value as well

Selenium/Python: Not able to find an element using any of the find_element_by_* methods

find element with xpath selenium

Not able to find element by XPATH using Appium / Python

Python Selenium Cannot find element using absolute xpath div

Not able to find element in selenium python

Selenium not able to find element by xpath

Finding Add To Cart button with selenium using find_element_by_xpath

Not able to find following element using id,Xpath,linkText

Locate an HTML element inside of the <iframe> by using Xpath (selenium c#)

Java selenium find element with xpath

Selenium find_element_by_xpath

Cannot find element within iframe using Selenium

how to find element using xpath selenium

selenium find element xpath

Cannot find element using xpath (Python and selenium)

Not able to select an element using xpath

Selenium not able to find element

Not able to locate an element within the IFrame (Selenium)

Not able to get element by xpath index (selenium)

Unable to locate element method using find element by Xpath in Selenium?

find_element_by_xpath() shows syntax error using Selenium with Python

Unable to find element by xpath using selenium

How to find element using the value attribute with Selenium and XPath

Selenium find(By.XPATH) cannot locate element using array of xpaths

How to find element and click by XPath in selenium using google colab cell?

TOP Ranking

HotTag

Archive