'How can i send keys to an iframe when iframe is the only element in the iframe

I have this iframe which is for inputting the card number.

I am trying this in chrome headless mode

<iframe hspace="0" vspace="0" frameborder="0" scrolling="no" allowtransparency="true" marginwidth="0" marginheight="0" 


Solution 1:[1]

Write the Xpath for that iframe like the below. As you mentioned

I have this iframe which is for inputting the card number.

so there is an attribute for for card number.

//iframe[@attribute='value']

Eg:

driver.switchTo().frame("iframe");

WebElement ele = driver.findElement(By.xpath("//iframe[@attribute='value']"));

ele.sendKeys('Text');

or

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@attribute='value']")));

WebElement inputtext = driver.findElement(By.xpath("//input[@attribute='value']"));

inputtext.sendKeys("text");

Hope this answer your question, please share the HTML from inspect element if this does not answer your question.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1