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
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
[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()
Thanks @bharathp666 driver.PageSource works really good to get all the element attributes.
Most helpful comment
Hi @bharathp666,
Can you try getting the
Toggle.ToggleStateattribute instead ofToggleState? E.g.Alternatively, toggle button control state can be inspected using the
Selectedproperty as shown in the following sample test: https://github.com/Microsoft/WinAppDriver/blob/v1.1/Tests/UWPControls/ToggleButton.cs#L97