硒可以在Outlook中在线查找find_element_by_xpath吗?

时间:2018-10-25 18:01:11

标签: python selenium xpath

我无法在Outlook的在线html中通过xpath或id查找元素。我正在使用硒和python。这是我写的。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException #imports

browser = webdriver.Chrome('C:\\Users\\...')
browser.get('https://www.office.com/...') #setup

#then some code to sign into outlook online

browser.find_element_by_xpath('//*[@id="_ariaId_64"]/div/div/div[1]')

browser.find_element_by_xpath('//*[@id="MailFolderPane.FavoritesFolders"]/div[19]')

browser.find_element_by_id('_ariaId_68') #attempts to find an element in outlook

这是我尝试访问的元素。我会发布整个html,但是有很多。我对所有事物代码都是全新的,所以请放心:)

<div>
   <div id="_ariaId_68" aria-expanded="false" draggable="true" dropzone="string:text/plain">
      <div autoid="_n_R" class="_n_44 canShowFavoritesAction" role="treeitem" aria-expanded="false" aria-labelledby="_ariaId_68.folder _ariaId_68.ucount" aria-haspopup="true" tabindex="-1">
         <div class="_n_S3 nowrap border-color-transparent _n_X3" style="padding-left: 4px;">
            <div class="_n_V3 _n_54">
               <span autoid="_n_S" class="_n_W3 ms-font-m ms-fwt-sl _n_Y3" id="_ariaId_68.folder" title="Sent Items">Sent Items</span>  
               <div class="_n_24 ms-bg-color-neutralLighter"> <span autoid="_n_T" class="ms-font-m _n_Z3 ms-fwt-sb ms-fcl-tp" aria-hidden="true"></span> </div>
               <span class="ms-font-s ms-fcl-ns" aria-hidden="true" aria-expanded="false" aria-haspopup="true" tabindex="-1">  </span>   <button autoid="_n_U" type="button" class="_n_34 ms-fwt-r ms-fcl-ns o365button hidden" style="display: none;" tabindex="-1"></button>  <span style="display: none;" aria-hidden="true"></span> 
            </div>
            <div class="_n_14 hidden"><button autoid="_n_V" type="button" class="_n_04 firefoxFavorite o365button" title="Remove from Favorites" aria-labelledby="_ariaId_69"><span class="_fc_3 owaimg ms-Icon--star ms-icon-font-size-18 ms-fcl-ns-b"> </span><span class="_fc_4 o365buttonLabel _fc_2" id="_ariaId_69" style="display: none;"></span></button></div>
         </div>
      </div>
   </div>
</div>

1 个答案:

答案 0 :(得分:0)

假设您要查找已发送商品的-web元素。

SENT ITEM链接似乎不是可见区域(当Inbox中有更多子文件夹时,通常会发生这种情况),因此在对元素执行任何操作之前,您首先要滚动查看该元素。

Here are the options to bring the element to visible area

尝试以下xpath delimiter // create or replace procedure insert_split_string(input text, d text) as declare position int = 1; newPosition int = -1; begin while newPosition != 0 loop newPosition = locate(d, input, position); if newPosition != 0 then insert into t values(substring(input, position, newPosition - position)); position = newPosition + 1; end if; end loop; -- Add the last delimited element insert into t values(substring_index(input, d, -1)); end // delimiter ; create table t(i int); call insert_split_string("1,2,3,4,5", ","); select * from t;