3

I wanted to fill in a input from website with html.

THis how the part of the website (https://account.protonmail.com/signup?language=de) looks like:

<div class="flex-item-fluid">
<input autocomplete="username" autocapitalize="off" autocorrect="off" spellcheck="false" aria-invalid="false" id="username" aria-describedby="id-1" class="w100 inputform-field" value="">
</div>

This my c# selenium part:

var elem = driver.FindElement(By.XPath("//*[@id='username']")).SendKeys("test");
// I also tried this:
var elem = driver.FindElement(By.XPath("//input[@id='username']")).SendKeys("test");

I hope somebody can help me.

3 Answers 3

1

The username field is in iframe

use the below xpath to switch to iframe first then you can continue with the rest of the code:

//iframe[@src]

something like this :

IWebElement iframe = driver.FindElement(By.Xpath("//iframe[@src]"));
driver.SwitchTo().Frame(iframe);

Also, I see multiple elements for username field. Always remember we should give more precedence to css_selector over xpath

Username field can be locate with this css:

body.color-norm.bg-norm input[id='username']

so in code something like this :

var elem = driver.FindElement(By.CssSelector("body.color-norm.bg-norm input[id='username']")).SendKeys("test");
var pass = driver.FindElement(By.CssSelector("input[id='password']")).SendKeys("password here");
Sign up to request clarification or add additional context in comments.

Comments

1

The element you are looking resides in an iframe so first switch the frame.

xPath for iframe:

//iframe[contains(@src,'Name=username')]

Then find the element using below xPath,

//input[@id='username']

Completed code:

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@src,'Name=username')]")));

var elem = driver.FindElement(By.XPath("//*[@id='username']")).SendKeys("test");

Comments

0

you can try this

var elem = driver.FindElement(By.CssSelector(".w100.inputform-field")).SendKeys("")

Here we search by class name, not by input name. Good Luck.

if it worked for you. USEFUL

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.