0

I am trying to input a certain text into the field 'payment__card-name', I have tried few webdriver code's but couldn't get through this issue,

This is the latest code i wrote, not sure what is going wrong in here, please help

//driver.findElement(By.xpath("//*div[@id='checkout-form-fieldset-payment']/fieldset/div[1]/div[2]/div/fieldset/div/div[1]/div[2]/input[@id='payment__card-name']")).sendKeys("add1");

Actual HTML code -

<body>
<div id="app-root">
<div class="">
<div class="c-navigation" role="banner">
<section class="app-checkout">
<section class="tickets-summary">
<div class="page-content page-content--mobile-full-width">
<div class="checkout-form">
<div class="app-checkout-form-feedback"/>
<form method="post" accept-charset="utf-8" id="checkout-form-passengers">
<form method="post" accept-charset="utf-8" id="checkout-form-contact-details">
<form method="post" accept-charset="utf-8" id="checkout-form-payment">
<div class="checkout-form-panel checkout-form-panel--no-padding app-payment" id="checkout-form-fieldset-payment">
<fieldset>
<legend class="checkout-form-panel--padding-fix checkout-form-panel__header h3">Payment</legend>
<div class="checkout-form-panel--padding-fix">
<div class="checkout-form-panel__col-from-medium-12 payment-switch__toggle">
<div>
<div class="payment-details payment__clearfix" id="checkout-form-fieldset-payment-details">
<fieldset>
<div class="">
<div class="payment__clearfix checkout-form-panel__col-from-small-6">
<div class="input__wrap">
<div class="input__wrap input__wrap--error">
<label for="payment__card-name">Name on card</label>
<input type="text" id="payment__card-name" name="payment__card-name" data-type="name" maxlength="50" value=""/>
<div class="input__feedback">Please enter the card holder's name exactly as it appears on the card</div>
</div>
</div>
supputuri
  • 13,644
  • 2
  • 21
  • 39
learnerhere
  • 1
  • 1
  • 2

1 Answers1

0

Here is the xpath that you can use.

//div[@id='checkout-form-fieldset-payment']/fieldset//input[@id='payment__card-name']

Screenshot: enter image description here

supputuri
  • 13,644
  • 2
  • 21
  • 39
  • Check [this](https://stackoverflow.com/questions/55870609/is-there-a-way-to-learn-xpath-without-using-firebug-or-xpath-as-firefox-is-not-s/55870909#55870909) post to know how to work with xpaths in the browser. – supputuri Aug 20 '19 at 03:07
  • Thank you This worked thank you. I have difficulties with yet another field :(:( https://stackoverflow.com/questions/57578578/selenium-unable-to-find-input-text-field-within-fieldset – learnerhere Aug 20 '19 at 17:12
  • If you feel the issue is resolved, please accept the answer by clicking on the hallow check mark below the down vote. [Upvote](https://stackoverflow.com/help/why-vote) the answer if this/any answer is/was helpful to you for the benefit of the future readers. – supputuri Aug 20 '19 at 17:30