Sabu Thaliyath
Sabu Thaliyath

Reputation: 31

Selenium: Matching content of dynamic div

I have a div that is dynamic. It's id is "logo" and it actually contains different logo based on the url I use. For example :-

<div id="header-container"> 
  <div id="header"> 
    <a href="/demo/"><div id="logo"></div></a> 

header.css file contain the logo div in detail

#logo {
width: 315px;
height: 88px;
background: url('/media/images/qt/Butto_qt.png') no-repeat -1339px 0px;
position: absolute;
left: 0;
}

I can invoke click on the xpath

"//div[@id='header-container']/div[@id='header']/a/div[@id='logo']" . 

However, what I want to figure out is how can I verify if the url contains "Butto_qt.png" ? If it is possible, how do I do it ?

Upvotes: 2

Views: 597

Answers (1)

Austin Hyde
Austin Hyde

Reputation: 27456

You can do this using a bit of Javascript:

window.getComputedStyle(document.getElementById('hlogo').childNodes[1]).backgroundImage

That should work in modern browsers.

Using selenium, you would use the assertEval method. For example, if you are using the PHPUnit Selenium extension:

$this->assertEval("window.getComputedStyle(document.getElementById('hlogo').childNodes[1]).backgroundImage",'Butto_qt.png');

Upvotes: 1

Related Questions