使用python使用selenium webdriver通过xpath查找元素

2024-10-01 04:47:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用python把文件上传到onedrive上。但我找不到上传按钮。元素在驱动程序中找到xpath,但在编写代码时引发超时异常。在

HTML代码:

<div class="CommandBarItem beak-anchor command is-focused" data-bind="css: { 'is-toggled': isOpen() || isToggled(), 'is-disabled': isDisabled, 'is-disabled-invisible': isInvisibleWhenDisabled, 'is-open': isOpen, 'is-focused': focused, 'CommandBarItem--hasPayload': $component.hasPayload, 'icon-only': hasIconOnly, 'is-current-view': isCurrentView, 'is-pivot': isCurrentView !== null, 'is-last-pivot': isLastPivot }, class: commandClass() ? 'od-Command--' + commandClass() : '', hasFocus: isActive, raiseEventOnChange: { eventName: 'layoutChange', bubbleEvent: true, data: layoutChanged }, dismiss: { isOpen: isOpen, isAutomatic: payload &amp;&amp; payload.autoDismiss, timeout: payload &amp;&amp; payload.timeout, dismissOnResize: false, dismissOnScroll: false }, with: targetCommand(), attr: { tabindex: tabindex, role: role, 'aria-label': $parent.accessibleLabel, 'aria-haspopup': visibleChildren().length > 0 || !!payload, 'aria-selected': isOpen(), 'aria-pressed': isToggled(), 'data-automationid': automationId, 'aria-expanded': visibleChildren().length > 0 ? isOpen().toString() : false, id: newFeatureExperienceAnchor }, teachingBubble: teachingBubble, tooltip: { content: $data.tooltip, isTooltipDisabled: isOpen }" tabindex="0" role="menuitem" aria-label="Upload. Upload files from your computer to this location" aria-haspopup="true" data-automationid="" aria-expanded="false">
   <div class="CommandBarItem-linkWrapper">
      <div class="CommandBarItem-link" data-bind="measure: { measure: $parent.measurementReady, async: true }, click: onClick, automation: 'link'" data-automationid="link">
         <!--ko if: $parent.icon--><span class="CommandBarItem-icon" data-bind="component: { name: 'od-icon-glyph', params: { icon: $parent.icon, badge: $parent.iconBadge } }, attr: { 'is-flipped': $parent.positionIconRight }"><i class="od-IconGlyph ms-Icon ms-Icon--Upload css-46 od-IconGlyph--visible" data-bind="class: iconClasses, attr: { 'data-icon-name': icon }, css: { 'od-IconGlyph--badged': badge, 'od-IconGlyph--visible': icon }, with: badge" data-icon-name="Upload"></i></span><!--/ko--><!--ko if: $parent.iconUrl--><!--/ko--><!--ko if: $parent.label()--><span class="CommandBarItem-commandText" data-bind="text: $parent.label, attr: { 'is-flipped': $parent.positionIconRight, 'role': $parent.hasDynamicText ? 'status' : null, 'aria-live': $parent.hasDynamicText ? 'polite' : null }, css: { 'CommandBarItem-commandText--isStrong': $parent.isStrong, 'ms-accessible': $parent.hasIconOnly() || !$parent.isLabelVisible() }">Upload</span><!--/ko--><!--ko if: visibleChildren().length && !hidesMenuChevron && !isCollapsed() && $parent.isLabelVisible()--><i class="od-CommandBarItem-down ms-Icon css-47" data-bind="class: getChevronDown()"></i><!--/ko-->
      </div>
      <!--ko if: $data.inputType() === ActionInputType.htmlFileUpload--><!--/ko--><!--ko if: $data.inputType() === ActionInputType.folderUpload--><!--/ko-->
   </div>
   <!--ko if: children().length && isOpen() && !isClipped()--><!--/ko--><!--ko if: $component.hasPayload--><!--/ko-->
</div>

我的代码:

^{pr2}$

但它不起作用并抛出超时异常


Tags: divdataifisbindcssclassko
1条回答
网友
1楼 · 发布于 2024-10-01 04:47:53

有一个解决方法,您可以获取元素的位置并使用该位置单击该元素。或者可以尝试使用javascript执行器调用onclick方法。在

相关问题 更多 >