MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / ClickAlertButtonUsingAccessibility

Method ClickAlertButtonUsingAccessibility

cpp/iedriver/Alert.cpp:475–530  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

473}
474
475int Alert::ClickAlertButtonUsingAccessibility(const std::string& automation_id) {
476 CComPtr<IUIAutomation> ui_automation;
477 HRESULT hr = ::CoCreateInstance(CLSID_CUIAutomation,
478 NULL,
479 CLSCTX_INPROC_SERVER,
480 IID_IUIAutomation,
481 reinterpret_cast<void**>(&ui_automation));
482
483 if (FAILED(hr)) {
484 LOGHR(WARN, hr) << "Unable to create global UI Automation object";
485 return EUNHANDLEDERROR;
486 }
487
488 CComPtr<IUIAutomationElement> parent_window;
489 hr = ui_automation->ElementFromHandle(this->alert_handle_,
490 &parent_window);
491 if (FAILED(hr)) {
492 LOGHR(WARN, hr) << "Unable to get automation object from window handle";
493 return EUNHANDLEDERROR;
494 }
495
496 CComVariant button_automation_id = automation_id.c_str();
497 CComPtr<IUIAutomationCondition> button_condition;
498 hr = ui_automation->CreatePropertyCondition(UIA_AutomationIdPropertyId,
499 button_automation_id,
500 &button_condition);
501 if (FAILED(hr)) {
502 LOGHR(WARN, hr) << "Unable to create button finding condition";
503 return EUNHANDLEDERROR;
504 }
505
506 CComPtr<IUIAutomationElement> button;
507 hr = parent_window->FindFirst(TreeScope::TreeScope_Children,
508 button_condition,
509 &button);
510 if (FAILED(hr)) {
511 LOGHR(WARN, hr) << "Unable to find button";
512 return EUNHANDLEDERROR;
513 }
514
515 CComPtr<IUIAutomationInvokePattern> button_invoke_pattern;
516 hr = button->GetCurrentPatternAs(UIA_InvokePatternId,
517 IID_PPV_ARGS(&button_invoke_pattern));
518 if (FAILED(hr)) {
519 LOGHR(WARN, hr) << "Unable to get invoke pattern on button";
520 return EUNHANDLEDERROR;
521 }
522
523 hr = button_invoke_pattern->Invoke();
524 if (FAILED(hr)) {
525 LOGHR(WARN, hr) << "Unable to invoke button";
526 return EUNHANDLEDERROR;
527 }
528
529 return WD_SUCCESS;
530}
531
532bool Alert::IsOKButton(HWND button_handle) {

Callers

nothing calls this directly

Calls 1

InvokeMethod · 0.80

Tested by

no test coverage detected