To get the value "8.37" from the "data-rating" attribute you can use the following line of code :
bot.FindElementByXPath("//div[@class='ch-rating']/div[@class='star-rating star-rating--alt star-rating--ch']").getAttribute("data-rating")
Update 1
Syntax :
var attribute = element.getAttribute(attributeName);
where
- attribute is a string containing the value of attributeName.
- attributeName is the name of the attribute whose value you want to get.
Update 2 :
As you are seeing Run-time error 438: Object doesn't support this property or method for HtmlElement.GetAttribute Method (String) here are some details :
Error 438 occurs when running a program in which a form is assigned to a variable and that variable is used to access a control on the form if the program is on a system running Windows 95 with Regional Settings set to a setting other than English (United States). The error text is:
Run-Time Error #438:
Object doesn't support this property or method
Resolution
There are two possible workarounds for this problem.
- Access the form directly rather than by a variable containing the form.
- Create property procedures in the form's code to provide access to the properties of the controls on the form.
Status
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem has been fixed in Windows 98.
Trivia
To reproduce this bug consistently, you will need HeapWalker, a utility that ships with the Windows 16-bit Software Development Kit and the 16-bit version of Visual C++.
Steps to Reproduce :
- From Control Panel, click Regional Settings to open the Regional Settings dialog box. Set the Regional Settings to English (Australian).
- Start the 16-bit edition of Visual Basic 4.0. If it is already running, select New Project from the File menu.
Source : FIX: Error 438"Object Doesn't Support This Property or Method"
WebElement we = driver.findElement(By.className("star-rating")); String rating = we.getAttribute("data-rating");driver.FindElementByCss("[data-rating]").Attribute("data-rating").