ajitjaiswal50 / selenium-vba

Automatically exported from code.google.com/p/selenium-vba
0 stars 0 forks source link

How to get title of a td element #67

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Operating system : Windows 7
.Net Framework version : 4.0
Office Version : 2003
SeleniumWrapper version : 2.5.0

What is your issue ?
I would like to read the title of an img in a td element.
Src, Title and alt could be different.

With IE-VBA I was using something like this 

Set HtmlElementStandard = 
IEDoc.getElementById("formQual").Children(6).Children(...)

Range("M17") = HtmlElementStandard.Title

Thanks

Original issue reported on code.google.com by religie...@gmail.com on 15 Apr 2014 at 8:28

Attachments:

GoogleCodeExporter commented 8 years ago
This is where Selenium is powerful as it's possible to use CSS or an XPath to 
locate an element.

Using an XPath (Selenium 2):
title = wd.findElementByXPath("//input[@id='FormQual']/div[@class='column 
sixtythree 
right']/div[@class='inner']/table[2]/tbody/tr[3]/td[8]").getAttribute("title")

Using an XPath (Selenium 1) :
title = wd.getAttribute("xpath=/input[@id='FormQual']/div[@class='column 
sixtythree right']/div[@class='inner']/table[2]/tbody/tr[3]/td[8]@title")

Using CSS (Selenium 2):
title = wd.findElementByCssSelector("input#FormQual > 
div.column.sixtythree.right > div.inner > table:nth-child(2) > tbody > 
tr:nth-child(3) > td:nth-child(8)").getAttribute("title")

Using CSS (Selenium 1):
title = wd.getAttribute("css=input#FormQual > div.column.sixtythree.right > 
div.inner > table:nth-child(2) > tbody > tr:nth-child(3) > 
td:nth-child(8)@title")

Locators may require some adjustments. You can easily get the Css locator in 
Firefox using the inspector:
 - Right click on the element and click on inspect element
 - Right click one the node and click "Copy Unique Selector"

Original comment by florentbr on 16 Apr 2014 at 12:20

GoogleCodeExporter commented 8 years ago
Thanks a lot, it is working well :)

Original comment by religie...@gmail.com on 16 Apr 2014 at 12:57

GoogleCodeExporter commented 8 years ago

Original comment by florentbr on 8 Sep 2014 at 5:40