0

I am having problems with selenium finding the input text field - 'billing-address__line-1 The code i used is -

driver.findElement(By.xpath(".//fieldset[.//input[@id='billing-address__line-1']]"))

HTML source

<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="billing-address" id="checkout-form-fieldset-billing-address">
<fieldset>
<legend class="h3 checkout-form-panel__header">Billing address</legend>
<div class="feedback-message" id="checkout-fieldset-feedback-billing-address">
<div class="checkout-form-panel__col-from-small-6 input__wrap input__wrap--error">
<label for="billing-address__line-1">Address line 1</label>
<input type="text" id="billing-address__line-1" name="billing-address" data-type="line1" maxlength="35" value=""/>
<div class="input__feedback">Just let us know your address</div>
</div>
<div class="checkout-form-panel__col-from-small-6 last input__wrap">
<div class="checkout-form-panel__col-from-small-6 input__wrap">
<div class="checkout-form-panel__col-from-small-6 last input__wrap">
<div class="checkout-form-panel__col-from-small-6 input__wrap">
<div class="checkout-form-panel__col-from-small-6 last input__wrap">

Error Message

Error - Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":".//fieldset[.//input[@id='billing-address__line-1']]"

Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
learnerhere
  • 1
  • 1
  • 2

2 Answers2

1

You can simply use id to find WebElement. Try:

driver.findElement(By.id("billing-address__line-1"))

And if you want to use xpath, it should be used as below:

driver.findElement(By.xpath("//fieldset//input[@id='billing-address__line-1']")
Krishna Majgaonkar
  • 1,532
  • 14
  • 25
0

To send a character sequence within the input text field associated with the <label> Address line 1 you can use either of the following Locator Strategies:

  • cssSelector:

    driver.findElement(By.cssSelector("label[for='billing-address__line-1']")).sendKeys("learnerhere");
    
  • xpath:

    driver.findElement(By.xpath("//label[@for='billing-address__line-1']")).sendKeys("learnerhere");
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352