AzMar
AzMar

Reputation: 71

Getting value of the element

I need to get the value of data-id in the HTML code below.

My attempted code is:

//p[contains(.,'Smart card')]/following-sibling::button[@data-id='633597015500043521']"));

My HTML code shown below:

    <form class="select-card-form" novalidate="" method="post">
        <input type="hidden" value="SmartCardSelect_3ca61d51-e601-40de-80fd-308bc47b52c6" name="FormName">
        <input type="hidden" value="d79cf158-93ad-4c77-b4bc-516ce8b28302" name="CardId">
        <div class="select-item ">
              <p>Smart card 1</p>
          <button class="submit-btn uniform-button button-smaller button-orange select-address" data-id="633597015500043521">
               <span>Select</span>
          </button>
      </div>
   </form>

Upvotes: 0

Views: 74

Answers (2)

BBP
BBP

Reputation: 46

Java code snippet

WebElement element  = driver.findElement(By.xpath("//form[@class='select-card-form']//div[@class='select-item ']//button"));
element.getAttribute("data-id");

Hope this helps.

Upvotes: 0

Ranjith&#39;s
Ranjith&#39;s

Reputation: 4740

Solution for this (JAVA):

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.select-item > button"))));
String value = element.getAttribute("data-id");

Upvotes: 1

Related Questions