Here is the full element I'm trying to click:
<div role="presentation" data-dyn-explicitcolumnwidth="custom" data-dyn-bind="
click: $data.ToggleMarkAllRecordsMode,
css: {
'is-loading': $data._isLoading
}
">
<div role="columnheader">
<span role="checkbox" data-dyn-bind="
checked: $data.MarkAllRecords,
skip: $dyn.util.markAllSkip($data),
attr: {'aria-label': $dyn.label('Grid_SelectAllRowsShortcut')}" aria-checked="false" tabindex="-1" aria-label="Select all rows">
<span ></span>
<span ></span>
</span>
</div>
</div>
I have tried using both ActionChains
and element.click()
to click on the parent element as well as each child element in the tree, using WebDriverWait for the element to be visible in the DOM. This element is a checkbox which appears near the top of the page, so it shouldn't have to be scrolled to. In order to test the various clicking methods I have a Chrome instance left open on a debugging port which allows me to execute commands in selenium over and over again without having to close/reopen the browser. This is also necessary due to the nature of the website I am trying to automate. This is within Microsoft's Dynamics 365 if that's any help.
Chrome window is opened with this console command:
chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\guest"
And then I connect the driver to it in python with this line:
chrome_options = Co()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
driver = Chrome(executable_path=chromedriver, options=chrome_options)
Using ActionChains(driver).move_to_element(element).click().perform()
I get the error [object HTMLDivElement] has no size and location
(or HTMLSpanElement
).
Using .click()
I just get element not interactable
.
I have also tried using the below execute_script()
commands:
driver.execute_script("arguments[0].click();", element)
driver.execute_script("arguments[0].setAttribute('aria-checked', 'true')", element)
In the latter example above, the element selected is the span
child element with :
element = driver.find_element_by_xpath("//span[@aria-label='Select all rows']")
However in both cases nothing happens and I get no error message. I can see that this span element is the element which has the event listener as well. So I'm doubly confused as to why no click methods work on this element.
To be sure, I am certainly able to manually click on this checkbox. Any help on this would be greatly appreciated, and please let me know if I can provide any additional information here. I'm not terribly experienced with HTML/Selenium.
EDIT: Below is the styles I copied for the span element that should be relevant (as mentioned it has the event listener):
font-style: normal;
font-variant: normal;
font-weight: 400;
border-collapse: collapse;
border-spacing: 0;
color: inherit;
user-select: none;
border: 0;
margin: 0;
padding: 0;
font-family: DynamicsSymbol;
font-size: 16px;
display: table;
width: 30px;
height: 30px;
cursor: pointer;
text-align: center;
I do see that it doesn't have a "visibility" style specified. Could that be the cause? And if so, how would I add "visibility" to the style sheet?
CodePudding user response:
I figured it out! The solution was much simpler than I was expecting. I just had to expand the xpath query to a parent element further up. The element I posted in my question above was just the checkbox itself, so I expanded the xpath to look first at the entire grid that the checkbox was part of. Here's the final xpath which worked for me:
"//div[@data-dyn-controlname='Grid']/div/div/div/div/div/span[@aria-label='Select all rows']"
I'm assuming that it wasn't working before because there were multiple elements loaded in the DOM that had the same tag @aria-label='Select all rows'
.