简体   繁体   中英

Java: getAttribute in Selenium

Currently I am working with the following HTML snippet:

<div class="cardEntry">
<!-- Balance Block Section (R)-->
<div class="balanceBLock">
<ul>
<li class="balanceText">Actual Balance</li>
<li class="balance">
<strong id="155555520be0019actualBalance">$1.00</strong>
</li>
<li class="balanceText">Available Balance</li>
<li class="balance">

I am trying to get the balance: $1.00 using the XPath:

.//*[@id='155555520be0019actualBalance'] 

and then attempting to obtain the dollar value using the method .getText however this does not return anything.

I can identify the element just fine using this XPath but it does not return the dollar value with getText method.

Can someone explain how to obtain this value?

Thanks

Looks like id is dynamic here.. use xpath like below with partial id

  //strong[contains(@id,'actualBalance')]

or else use

//li[. = 'Actual Balance']/following-sibling::li/strong

specified by alecxe in comment.

尝试使用以下任意值的getAttribute():“ value”,“ innerText”,“ innerHTML”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM