2

I'd like to open Google using Selenium webdriver and replace the Google logo with some other image. Of course I don't mean to change it on the server I want to do it locally in my web browser.

Is it doable?

Radu Diță
  • 13,476
  • 2
  • 30
  • 34
Michał Witanowski
  • 602
  • 3
  • 8
  • 22
  • Why selenium?.. It is a testing tool, I don't think that image switch is something connected with testing. You can do it via JS in 1-2 lines though.. – user Jun 30 '15 at 12:21
  • I want to get live version of google that's why i use selenium to open it with webdriver then i want to replace image and do some more actions with selenium. – Michał Witanowski Jun 30 '15 at 12:36
  • 2
    Add some JS that will replace an attribute with the value you need: http://stackoverflow.com/questions/8473024/selenium-can-i-set-any-of-the-attribute-value-of-a-webelement-in-selenium - in your case this attribute will be the img value. – user Jun 30 '15 at 12:37
  • Thank you, that's exactly what i was looking for. – Michał Witanowski Jun 30 '15 at 12:59
  • @ConstantineNovykov why don't you turn the comment into an answer, and the OP can accept it? – Radu Diță Jun 30 '15 at 18:15

2 Answers2

2

Add some JS that will replace an attribute with the value you need: Selenium: Can I set any of the attribute value of a WebElement in Selenium? - in your case this attribute will be the img src value.

Community
  • 1
  • 1
user
  • 3,058
  • 23
  • 45
0

You can use the javascript executor to change the properties of the WebPage.

WebElement element = driver.findElement(By.xpath("//div[@id='lga']//img"));    
((JavascriptExecutor)driver).executeScript("arguments[0].src='"+pathToNewImage+"'", imageElement);
StrikerVillain
  • 3,719
  • 2
  • 24
  • 41