1

I am testing a website where the user has an option to change the input fields to Textbox and Dropdown. Whether the user changes it to dropdown or textbox, the xpath for the input field is the same. So, I am not sure how to write the test steps for this situation.

I would like to do something like:

if (dropdown present)
{
   Selenium.Select("dropdown xpath", "option");
}

else if (textbox present)
{
   Selenium.Type("texbox xpath", "option");
}

Can anyone please help me out? Is there a way in Selenium to check if a input is of type "text"?

2 Answers 2

1

You can use selenium.isElementPresent(locator), enclosed within you if (..) construct to check for the presence of an element, and perform operations accordingly.

Sign up to request clarification or add additional context in comments.

Comments

1

I didn't see a simple property in selenium, but you can definitely get it by calling javascript:

IWebElement element = ...

string tagName = ((IJavaScriptExecutor)webDriver).ExecuteScript("return arguments[0].tagName", element).ToString();

Another alternative is to create 2 xpaths that will only work for one or the other, and attempt to find the textbox within a try/catch. If it hits the catch, then search for the dropdown instead.

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.