0

What I get so far:

 def picture(self):
    path = "/home/user/Desktop/cat.jpg"
    path2 = "/home/user/Desktop/puppy.jpg"
    pictureName  = self.driver.find_element_by_xpath('//*[@id="easSettingAvatar"]')
    self.captureScreen('picture', 1)
    editPhoto.send_keys(path)
    time.sleep(5)
    print(pictureName)
    self.captureScreen('picture', 2)
    editPhoto.send_keys(path2)
    time.sleep(5)
    print(pictureName)

So basically, when I select CSS or Xpath of the element which contains src, it prints completely different information like:

<selenium.webdriver.firefox.webelement.FirefoxWebElement (session="bba710d8-ac5e-4e96-b946-14b3eda53cca", element="6d243513-8109-495e-a7a4-e4d218bbbd9a")>

Buaban
  • 5,029
  • 1
  • 17
  • 33
NatNat
  • 23
  • 2
  • 8
  • Of course `driver.find_element_by_xpath` returns a `WebElement` object. What kind of result were you expecting? Unparsed HTML source? – Aran-Fey Jun 20 '17 at 23:01
  • I am expecting to see this: or just src – NatNat Jun 20 '17 at 23:12
  • Possible duplicate of [Get HTML Source of WebElement in Selenium WebDriver using Python](https://stackoverflow.com/questions/7263824/get-html-source-of-webelement-in-selenium-webdriver-using-python) – Aran-Fey Jun 20 '17 at 23:14
  • Thank you, I changed my code to: pictureName = self.driver.find_element_by_xpath('//*[@id="easSettingAvatar"]') source_code = pictureName.get_attribute("outerHTML") and the outcome I got is now: – NatNat Jun 20 '17 at 23:22
  • Any ideas how to get rid of the last part, which is " "? – NatNat Jun 20 '17 at 23:25
  • Well, you have _two_ `print`s in your code... Have you updated both of them? Maybe remove the second one? – Aran-Fey Jun 20 '17 at 23:27
  • thanks, it was a mess. all fixed now – NatNat Jun 20 '17 at 23:36

1 Answers1

0

You have to print attribute of the WebElement instead of print the WebElement.

def picture(self):
    path = "/home/user/Desktop/cat.jpg"
    path2 = "/home/user/Desktop/puppy.jpg"
    pictureName  = self.driver.find_element_by_xpath('//*[@id="easSettingAvatar"]')
    self.captureScreen('picture', 1)
    editPhoto.send_keys(path)
    time.sleep(5)
    print(pictureName.get_attribute('outerHTML'))
    print(pictureName.get_attribute('src'))
    self.captureScreen('picture', 2)
    editPhoto.send_keys(path2)
    time.sleep(5)

The result should be

<img id="easSettingAvatar" src="eas.eightdevelopment.net/getAvatar/…; 
eas.eightdevelopment.net/getAvatar/…
Buaban
  • 5,029
  • 1
  • 17
  • 33