0

In Selenium, I can locate an item and its HTML this way:

driver.get('http://www.google.com/ncr');

driver.findElement(webdriver.By.id('hplogo')).getAttribute('outerHTML').then(
  function(html) {
    console.log(html);
  });

Is it possible for me to retrieve the file type of the HTML I am getting? For example, if the HTML is logged as follows:

<video src="http://www.myvideo.com/video.webm"></video>

I would get the following output:

webm
mcranston18
  • 4,680
  • 3
  • 36
  • 37

1 Answers1

1

What you are finding with the getAttribute function is merely a string.

The actual file type and if it exists at all are not found at this point.

However, in your example, you now have the string that contains the file you are looking for and can use java to substring off the last part filename.

String type;
String attribute = driver.findElement(webdriver.By.id('hplogo')).getAttribute('outerHTML');
int dotLocation = attribute.lastIndexOf(".");
if(dotLocation != -1 && dotLocation != attribute.length -1){
    type = attribute.substring(dotLocation + 1, attribute.length());
} else {
    type = "Unknown";
}
useSticks
  • 883
  • 7
  • 15
  • Yeah, getAttribute returning a string means my only option is parsing it. Appreciate your answer, although java code for a nodeJS question doesn't help too much ;) – mcranston18 Jan 22 '14 at 21:03
  • lol. Point. I missed the NodeJS portion of it and the syntax was close enough that I missed it there as well. – useSticks Jan 22 '14 at 21:05