ONDEV
ONDEV

Reputation: 566

Want to Grab Text Returned From A Page Using VBA, Excel, and Selenium

I am using Excel 2010, VBA, and Selenium (due to IE not handling the target web page properly). So I switched to Selenium.

I have steps 1 and 2 working.

  1. Insert the domain name into the "domainToCheck" textbox
  2. Click the "GoValue™" button
  3. Get the Estimated Value from the result page

The page returns an appraised value and its that value that I would like to capture and put into my spreadsheet. My code is as follows:

Public Sub getAppraisal()

Dim oBrowser    As New WebDriver
Dim oElement    As WebElement

Dim sEstimate   As String

Dim oCell       As Range
Dim oRng        As Range

oBrowser.Start "Firefox"

Set oRng = Range(Worksheets("sheet1").Range("A2"), Worksheets("sheet1").Range("A2").End(xlDown))

For Each oCell In oRng
    'GO TO THE APPRAISAL WEBPAGE
    oBrowser.Get "https://www.godaddy.com/domain-value-appraisal"
    'ENTER THE DOMAIN NAME TO BE APPRAISED
    oBrowser.FindElementByName("domainToCheck").SendKeys (oCell.Value)
    'CLICK THE SUBMIT BUTTON
    oBrowser.FindElementByClass("input-group-btn").Click
    oBrowser.Wait 1000
    'GRAB THE ESTIMATED VALUE
    sEstimate = oBrowser.FindElementByClass("dpp-price price").Value '<--- ERROR IS HERE "INVALID SELECTOR ERROR"

    'POPULATE THE ESTIMATE NEXT TO THE DOMAIN NAME ON THE SHEET
    oCell.Offset(0, 1).Value = CCur(sEstimate)
Next

oBrowser.Quit
Set oBrowser = Nothing

End Sub

The spreadsheet is as follows:

enter image description here

The HTML DIV that contains the result is as follows:

<div class="exact-domain-result"><div class="d-block wrap-text"><h1 class="m-b-1">activefs.com</h1></div><h3><span><img src="https://img1.wsimg.com/DomainValuation/icn-godaddy-valuation.png" style="padding-bottom: 7px;"> </span><span class="dpp-price"><span class="text-muted"><span>Estimated Value:</span></span></span> <span class="dpp-price price"><strong>$1,774</strong></span> <span id="currencyLabel"></span><sup><span><span class="d-block-inline valuation-tooltip"><span> <span style="cursor: pointer; outline: medium none;" class="uxicon uxicon-help" aria-haspopup="true" role="button"></span></span></span></span></sup></h3></div>

Upvotes: 0

Views: 587

Answers (1)

supputuri
supputuri

Reputation: 14145

Root Cause:

If you look at the span html node dpp-price price is not a single class, you have dpp-price and price classes. And you are trying to find the element considering it has a single class, that's the reason why you will get exception when selenium try to find the element.

How to resolve the issue:

You can use the css selector/xpath to find the element as shown below.

# css selector
.dpp-price.price
#xpath
//span[@class='dpp-price price']

Upvotes: 2

Related Questions