Asserting the background image of a page with selenium

妖精的绣舞 提交于 2020-01-16 18:26:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!