2017-06-20 2 views
0

Ce que je reçois à ce jour:Comment puis-je obtenir le code HTML d'un WebElement ou d'un attribut d'un 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) 
    self.captureScreen('picture', 2) 
    editPhoto.send_keys(path2) 
    time.sleep(5) 
    print(pictureName) 

Donc, fondamentalement, lorsque je sélectionne CSS ou XPath de l'élément qui contient Src, il imprime des informations complètement différentes comme:

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

+0

Bien sûr, 'driver.find_element_by_xpath' retourne un objet' WebElement'. Quel genre de résultat attendiez-vous? Source HTML non analysée? –

+0

Je m'attends à voir ceci: ou juste src – NatNat

+0

Possible copie de [Obtenir la source HTML de WebElement dans Selenium WebDriver en utilisant Python] (https://stackoverflow.com/questions/7263824/get-html-source-of-webelement -in-selenium-webdriver-using-python) –

Répondre

0

Vous avoir à imprimer l'attribut de WebElement au lieu d'imprimer 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) 

Le résultat devrait être

<img id="easSettingAvatar" src="eas.eightdevelopment.net/getAvatar/…; 
eas.eightdevelopment.net/getAvatar/…