我無法確定我正在處於自動化過程中的網站上的添加按鈕。 Python,Webdriver。 硒IDE提供了以下XPath:我正在嘗試爲Xpath或CSS添加按鈕
adminAdd_button = driver.find_element_by_xpath("//button[@type='button'])[33]")
adminAdd_button.click()
我收到以下錯誤,當我在我的蟒蛇,webdriver的代碼試試這個XPath。
selenium.common.exceptions.InvalidSelectorException: Message: The xpath expression '//button[@type='button'])[33]' cannot be evaluated or does notresult in a WebElement
我也曾嘗試下面的XPath沒有運氣:
driver.find_element_by_xpath("//div[. = 'Add']")
有誰知道的Xpath我可以用這個嗎?或CSS作爲CSS比Xpath更快執行。謝謝。
HTML源代碼如下所示(Add位於源代碼的底部)。有這麼多的div標籤:
<html style="overflow: hidden;">
<head>
<body style="margin: 0px;">
<iframe id="__gwt_historyFrame" style="position: absolute; width: 0; height: 0; border: 0;" tabindex="-1" src="javascript:''">
<noscript> <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif;"> Your web browser must have JavaScript enabled in order for this application to display correctly.</div> </noscript>
<script src="spinner.js" type="text/javascript">
<script type="text/javascript">
<script src="ClearCore/ClearCore.nocache.js" type="text/javascript">
<script defer="defer">
<iframe id="ClearCore" src="javascript:''" style="position: absolute; width: 0px; height: 0px; border: medium none;" tabindex="-1">
<div style="position: absolute; z-index: -32767; top: -20cm; width: 10cm; height: 10cm; visibility: hidden;" aria-hidden="true"> </div>
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"> </div>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"> </div>
<div style="position: absolute; overflow: hidden; left: 1px; top: 1px; right: 1px; bottom: 1px;">
<div class="gwt-TabLayoutPanel" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"> </div>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; height: 30px;">
<div class="gwt-TabLayoutPanelTabs" style="position: absolute; left: 0px; right: 0px; bottom: 0px; width: 16384px;">
<div class="gwt-TabLayoutPanelTab GAT4PNUK" style="background-color: rgb(254, 255, 238);">
<div class="gwt-TabLayoutPanelTabInner">
</div>
<div class="gwt-TabLayoutPanelTab GAT4PNUK" style="background-color: rgb(254, 255, 238);">
<div class="gwt-TabLayoutPanelTabInner">
</div>
<div class="gwt-TabLayoutPanelTab GAT4PNUK" style="background-color: rgb(254, 255, 238);">
<div class="gwt-TabLayoutPanelTabInner">
</div>
<div class="gwt-TabLayoutPanelTab GAT4PNUK" style="background-color: rgb(254, 255, 238);">
<div class="gwt-TabLayoutPanelTabInner">
</div>
<div class="gwt-TabLayoutPanelTab GAT4PNUK" style="background-color: rgb(254, 255, 238);">
<div class="gwt-TabLayoutPanelTabInner">
</div>
<div class="gwt-TabLayoutPanelTab GAT4PNUK" style="background-color: rgb(254, 255, 238);">
<div class="gwt-TabLayoutPanelTabInner">
<div class="gwt-HTML">Operations</div>
</div>
</div>
<div class="gwt-TabLayoutPanelTab GAT4PNUK gwt-TabLayoutPanelTab-selected" style="background-color: rgb(254, 255, 238);">
<div class="gwt-TabLayoutPanelTabInner">
<div class="gwt-HTML">Administration</div>
</div>
</div>
</div>
</div>
<div style="position: absolute; overflow: hidden; left: 0px; top: 30px; right: 0px; bottom: 0px;">
<div class="gwt-TabLayoutPanelContentContainer" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"> </div>
<div style="position: absolute; overflow: hidden; left: -100%; top: 0%; width: 100%; height: 100%; display: none;">
<div style="position: absolute; overflow: hidden; display: none; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; overflow: hidden; display: none; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; overflow: hidden; display: none; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; overflow: hidden; display: none; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; overflow: hidden; left: 100%; top: 0%; width: 100%; height: 100%; display: none;">
<div class="gwt-TabLayoutPanelContent" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; display: none;" aria-hidden="true">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"> </div>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; height: 35px;">
<div style="position: absolute; overflow: hidden; left: 0px; top: 35px; right: 0px; bottom: 0px;">
<div class="gwt-SplitLayoutPanel" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"> </div>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; bottom: 0px; width: 160px;">
<div style="position: absolute; overflow: hidden; left: 160px; top: 0px; bottom: 0px; width: 8px;">
<div style="position: absolute; overflow: hidden; left: 168px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"> </div>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"> </div>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; height: 24px;">
<div style="position: absolute; overflow: hidden; left: 0px; top: 24px; right: 0px; height: 24px;">
<div style="position: absolute; overflow: hidden; left: 0px; top: 48px; right: 0px; bottom: 0px;">
<div class="gwt-TabLayoutPanel" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"> </div>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; height: 30px;">
<div style="position: absolute; overflow: hidden; left: 0px; top: 30px; right: 0px; bottom: 0px;">
<div class="gwt-TabLayoutPanelContentContainer" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div style="position: absolute; overflow: hidden; left: 0%; top: 0%; width: 100%; height: 100%;">
<div class="gwt-TabLayoutPanelContent" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;" aria-hidden="false">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"> </div>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; height: 35px;">
<div style="position: absolute; overflow: hidden; left: 0px; top: 35px; right: 0px; bottom: 0px;">
<div class="gwt-SplitLayoutPanel" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"> </div>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; bottom: 0px; width: 160px;">
<div style="position: absolute; overflow: hidden; left: 160px; top: 0px; bottom: 0px; width: 8px;">
<div style="position: absolute; overflow: hidden; left: 168px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"> </div>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="right: 0px; bottom: 0px; position: absolute; left: 0px; top: 0px;">
<div style="position: absolute; z-index: -32767; top: -20ex; width: 10em; height: 10ex; visibility: hidden;" aria-hidden="true"> </div>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; height: 24px;">
<div class="workspacetoolbar" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div>
<div style="position: absolute; top: 3px; left: 5px;">
<span class="gwt-InlineLabel" style="font-weight: bold; color: black; margin-right: 5px; margin-left: 20px;">Projects</span>
<div class="GAT4PNUMP">
<button class="gwt-Button" type="button">
<div style="position: absolute; margin-left: 2px;">
<div id="prueba" class="gwt-HTML" style="margin-left: 15px;">Add...</div>
</button>
<button class="gwt-Button" type="button" disabled="">
<button class="gwt-Button workspacebuttontext75" type="button" title="Delete" disabled="">Delete ▼</button>
<div class="GAT4PNUMP">
如果你有* *類爲什麼不只是做:'find_element_by_xpath(「//按鈕[@類=‘GWT-按鈕’] 「)'? – Anzel
,但確保您*實際*切換到iframe。 – Anzel
在選擇器中使用索引是不好的做法,恕我直言。如果您提供了更多所需的div內容,我可以嘗試爲您構建一個有效的css選擇器 –