Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
499 views
by Contributing Tester (82 points)
retagged by
How Can I find a value from example of using Xpath.

I need to get number of adults ?

http://www.easyjet.com/en/

<input id="Adults-257083" class="passenger-amount ng-pristine ng-valid ng-valid-pattern ng-valid-maxlength ng-valid-amount ng-touched" type="number" ej-prevent-non-numeric-keys="" ng-change="ResetIfNotANumber()" ng-model-options="{allowInvalid: true, updateOn: 'blur'}" ng-model="Passengers[Type]" ej-valid-on-invalid="ValidAmount(true)" ej-valid-key="amount" ej-valid="ValidAmount()" maxlength="2" inputmode="numeric" pattern="^\d*$" name="Adults" aria-invalid="false" style=""/>
by The go-to Tester (181 points)
your question is not clear yet. Are trying to automate? If so, what language and framework are you using? Kindly explain your problem in details.
by Contributing Tester (82 points)
I need to get value from that webelement. I need to get number.

2 Answers

0 like 0 dislike
by The go-to Tester (181 points)

If you are using chrome, you can do right click > inspect element. Now you will see element highlited in inspect window. Here you can right click > copy and "copy xpath".

Here is your xPath

//*[@id="Adults-906830"]

Also, I see that your id is dynamic. So, you can try using regular expression.

//*[starts-with(@id,"Adults-\d+")]

by Contributing Tester (82 points)
Hi,

No I can't help with that :(
Look example :

Text of button:
Console.WriteLine(ObjectRepository.Driver.FindElement(By.XPath("//button[@class='ej-button rounded-corners arrow-button search-submit']")).Text);
Results: Show flights

Text(number) of adults:
Console.WriteLine(ObjectRepository.Driver.FindElement(By.XPath("//input[@id='Adults-926048']")).Text);
Results: Error
by The go-to Tester (181 points)
Do you want to try.

Console.WriteLine(ObjectRepository.Driver.FindElement(By.XPath("//*[starts-with(@id,\"Adults-\d+\")]")).Text);

Let me know how it goes.
by Contributing Tester (82 points)
Error    CS1009    Unrecognized escape sequence    SeleniumWebdriver
Error in char "d"
0 like 0 dislike
by Contributing Tester (13 points)
From console, just get the element using name

Webelement Adultnumber = Driver.FindElement(By.name('Adults")).getText;

u can access the number using "adultnumber"

where u can get the number for that webelement.

Using xpath =//*[@name="Adults"]


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...