0

Here I have a scenario, where I need to check variable value from view page source code. For ex:- For the below URL https://www.seniorhousingnet.com/seniorliving-detail/overture-fair-ridge-62-apartment-homes_3955-fair-ridge-drive_fairfax_va_22033-581333

Click view page source, then find an a variable "leadtype"

enter image description here

I know, we need to use driver.getpagesource() to get view page source in selenium, But I need to check leadtype value for a particular property, If it is SHN-enhanced, The logic will be different, If leadtype value is different then we need to apply another logic. Just please let me know how to check leadtype value in this scenario.

Matsemann
  • 21,083
  • 19
  • 56
  • 89

2 Answers2

1

Hope you are working in java, Java provides multiple libraries for reading an html content. once you get the page source, make an html object , parse it and reach the desired node. when you finally got the node of your choice you can get its attributes , its value and other properties as well

<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.2</version>

Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
log(doc.title());
Elements newsHeadlines = doc.select("#mp-itn b a");
for (Element headline : newsHeadlines) {
  log("%s\n\t%s", 
   headline.attr("title"), headline.absUrl("href"));
}

JSOUP library

jsoup tutorial

baeldung jsoup tutorial

there was also a stackoverflow question for html parser, Please do check it once link

Saurabh Verma
  • 627
  • 1
  • 14
  • 27
0

You don't have to parse the HTML to get the value. That JS line is actually executed and the adobeDTM variable then holds the data. You can access that using adobeDTM.leadType but you will need to execute JavaScript in order to obtain the value.

String leadType = (String) ((JavascriptExecutor)driver).executeScript("return adobeDTM.leadType"));

leadType now contains "shn-enhanced" (according to my code execution).

JeffC
  • 22,180
  • 5
  • 32
  • 55