WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

Certain Element attributes are not obtained by get_attribute()

Open bharathp666 opened this issue 7 years ago • 3 comments

Certain Element attributes are not obtained by get_attribute(self, name). The value is null or None. The attributes are present in the source. I'm trying to fetch the 'ToggleState' of a Button but turns out I always get None. Is there a solution?

From Python Bindings: self.driver.find_element_by_accessibility_id("openOnStartup").get_attribute('ToggleState')

{
    "AcceleratorKey": null,
    "AccessKey": null,
    "AutomationId": "openOnStartup",
    "ClassName": "ToggleSwitch",
    "FrameworkId": "XAML",
    "HasKeyboardFocus": "true",
    "HelpText": null,
    "IsContentElement": "true",
    "IsControlElement": "true",
    "IsEnabled": "true",
    "IsKeyboardFocusable": "true",
    "IsOffscreen": "false",
    "IsPassword": "false",
    "IsRequiredForForm": "false",
    "ItemStatus": null,
    "ItemType": null,
    "LocalizedControlType": "toggle switch",
    "Name": null,
    "Orientation": "None",
    "ProcessId": "16624",
    "RuntimeId": "42.5310242.4.84",
    "x": null,
    "y": null,
    "width": null,
    "height": null,
    "ToggleState": null,
    "IsAvailable": null
}

From Source: driver.page_source

...
<Button 
	AcceleratorKey="" 
	AccessKey="" 
	AutomationId="openOnStartup" 
	ClassName="ToggleSwitch" 
	FrameworkId="XAML" 
	HasKeyboardFocus="False" 
	HelpText="" 
	IsContentElement="True" 
	IsControlElement="True" 
	IsEnabled="True" 
	IsKeyboardFocusable="True" 
	IsOffscreen="False" 
	IsPassword="False" 
	IsRequiredForForm="False" 
	ItemStatus="" ItemType="" 
	LocalizedControlType="toggle switch" 
	Name="" 
	Orientation="None" 
	ProcessId="6996" 
	RuntimeId="42.3019514.4.21"
	x="89" 
	y="114" 
	width="76" 
	height="32" 
	ToggleState="Off" 
	IsAvailable="True" 
/>
...

WinAppdriver 1.1, Appium 1.9.1, Python 3.7.0

bharathp666 avatar Feb 07 '19 17:02 bharathp666

Hi @bharathp666,

Can you try getting the Toggle.ToggleState attribute instead of ToggleState? E.g.

self.driver.find_element_by_accessibility_id("openOnStartup").get_attribute('Toggle.ToggleState')

Alternatively, toggle button control state can be inspected using the Selected property as shown in the following sample test: https://github.com/Microsoft/WinAppDriver/blob/v1.1/Tests/UWPControls/ToggleButton.cs#L97

timotiusmargo avatar Feb 13 '19 09:02 timotiusmargo

[Solved] @timotiusmargo both worked! thanks

self.driver.find_element_by_accessibility_id("openOnStartup").get_attribute('Toggle.ToggleState')
self.driver.find_element_by_accessibility_id("openOnStartup").is_selected()

bharathp666 avatar Feb 15 '19 17:02 bharathp666

Thanks @bharathp666 driver.PageSource works really good to get all the element attributes.

MarcoDeJesus avatar Feb 19 '20 16:02 MarcoDeJesus