问题
I have an app in which the user can change the background image of their profile page. Therefore, I wasnt to assert that, when the user changes the image, the image actually changes. I can't for the life of me figure out a css selector or xpath to do the job. This is the HTML I have:
<body style="background:#FFFFFF url(/uploads/images/000/000/002/original.png?1257966819) no-repeat 0 0;" class="users users-show-edit layout-main-with-sidebar" id="users-edit">
Any sugestions?
回答1:
I've used the following, but I believe it may need tweaking to work across multiple browsers - I primarily test in Firefox:
selenium.getEval("this.findEffectiveStyleProperty(this.browserbot.findElement(\"" + locator + "\"), \"backgroundImage\")");
回答2:
I went with this in the end, bit of a hack, but does the job:
html = browser.get_html_source
assert html.include?("#{@background.background_image.url}")
来源:https://stackoverflow.com/questions/1799173/asserting-the-background-image-of-a-page-with-selenium