簡體   English   中英

Python Selenium 使用絕對 xpath div 找不到元素

[英]Python Selenium Cannot find element using absolute xpath div

我已經閱讀了一天多的網頁和 stackoverflow 帖子,我已經到了我“大部分”得到動態 xPath 來點擊但它沒有點擊的地步……

目標是動態地從交易視圖邀請列表中刪除一個私人指標的用戶。 單擊管理訪問會創建一個彈出窗口,在其中輸入或刪除用戶。 我可以很好地添加用戶,但是嘗試單擊列表中用戶名旁邊的“x”確實很困難,因為嵌套的 div 是相同的,除了自定義數據用戶名標簽和跨度文本值。

簡而言之,我可以獲得絕對的 xpath 並嘗試單擊它,但我得到一個找不到元素,我知道這不是真的。

刪除用戶 arguments

unsubscribed - 傳遞給從電視中刪除的用戶列表
htmlsource - self.driver.page_source傳遞給每個用戶刪除按鈕抓取 xpath。

設置

Python 3.7.3+ Selenium BeautifulSoup

錯誤信息

<div class="tv-dialog js-dialog tv-dialog--popup i-focused ui-draggable" tabindex="-1" style="width: calc(100% - 20px); max-width: 500px; top: 459px; left: 265px; z-index: 112;">
   <div class="tv-dialog__section tv-dialog__section--title js-dialog__drag tv-dialog__grab ui-draggable-handle">
      <div class="js-title-text tv-dialog__title">Manage Pine Script Access</div>
   </div>
   <div>
      <div>
         <div class="tv-dialog__section tv-manage-access-dialog__section js-search-placeholder">
            <div class="tv-search-row">
               <input class="tv-search-row__input js-input-control" type="text" name="q" value="" autocomplete="off" data-role="search" placeholder="Add user">
               <span class="tv-search-row__input-reset i-hidden js-reset-button">
                  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 95.939 95.939" width="95.939" height="95.939">
                     <path d="M62.82 47.97l32.53-32.534a2 2 0 0 0 0-2.828L83.332.586a2 2 0 0 0-2.827 0L47.97 33.12 15.435.587c-.75-.75-2.078-.75-2.828 0L.587 12.607a2 2 0 0 0 0 2.83L33.12 47.97.588 80.504a2 2 0 0 0 0 2.828l12.02 12.02a1.997 1.997 0 0 0 2.83 0L47.97 62.818l32.535 32.535a2 2 0 0 0 2.827 0l12.02-12.02c.78-.783.78-2.05 0-2.83L62.82 47.97z"></path>
                  </svg>
               </span>
               <span class="tv-search-row__search-icon">
                  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18 18" width="18px" height="18px">
                     <path fill-rule="evenodd" d="M12.5 11h-.79l-.28-.27A6.47 6.47 0 0 0 13 6.5 6.5 6.5 0 1 0 6.5 13c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L17.49 16l-4.99-5zm-6 0C4.01 11 2 8.99 2 6.5S4.01 2 6.5 2 11 4.01 11 6.5 8.99 11 6.5 11z"></path>
                  </svg>
               </span>
               <div class="tv-username-hint-list js-hidden tv-username-hint-list--full-border" style="left: 0px; top: 100%; width: 65%; z-index: 100;"></div>
            </div>
         </div>
         <div class="tv-dialog__section tv-manage-access-dialog__section">
            <div class="tv-text tv-manage-access-dialog__user-list-header js-user-list-header">14 users have access</div>
            <div class="tv-manage-access-dialog__user-list-container tv-dialog__scroll-wrap js-dialog__scroll-wrap wrapper-2KWBfDVB- sb-scroll-active" style="">
               <div class="tv-dialog__scroll-wrap-inner js-user-list-attach" style="bottom: auto; top: 0px;">
                  <div class="tv-manage-access-dialog__user-list-body js-user-list">
                     <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="snub-fighter">
                        <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%2890,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3ES%3C/text%3E%3C/svg%3E"><span>snub-fighter</span></div>
                        <div class="tv-manage-access-dialog__user-remove-column">
                           <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access">
                              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10">
                                 <g fill="none" stroke="#758696" stroke-width="2">
                                    <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path>
                                 </g>
                              </svg>
                           </div>
                        </div>
                     </div>
                     <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="KingThies_">
                        <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="https://s3.tradingview.com/userpics/1662357-tYZf.png"><span>KingThies_</span></div>
                        <div class="tv-manage-access-dialog__user-remove-column">
                           <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access">
                              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10">
                                 <g fill="none" stroke="#758696" stroke-width="2">
                                    <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path>
                                 </g>
                              </svg>
                           </div>
                        </div>
                     </div>
                     <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="Eniesee_ldk">
                        <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%28312,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3EE%3C/text%3E%3C/svg%3E"><span>Eniesee_ldk</span></div>
                        <div class="tv-manage-access-dialog__user-remove-column">
                           <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access">
                              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10">
                                 <g fill="none" stroke="#758696" stroke-width="2">
                                    <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path>
                                 </g>
                              </svg>
                           </div>
                        </div>
                     </div>
                     <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="sugarjun">
                        <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%289,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3ES%3C/text%3E%3C/svg%3E"><span>sugarjun</span></div>
                        <div class="tv-manage-access-dialog__user-remove-column">
                           <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access">
                              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10">
                                 <g fill="none" stroke="#758696" stroke-width="2">
                                    <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path>
                                 </g>
                              </svg>
                           </div>
                        </div>
                     </div>
                     <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="dijkie">
                        <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%28144,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3ED%3C/text%3E%3C/svg%3E"><span>dijkie</span></div>
                        <div class="tv-manage-access-dialog__user-remove-column">
                           <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access">
                              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10">
                                 <g fill="none" stroke="#758696" stroke-width="2">
                                    <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path>
                                 </g>
                              </svg>
                           </div>
                        </div>
                     </div>
                     <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="PaulAdelaar">
                        <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%2884,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3EP%3C/text%3E%3C/svg%3E"><span>PaulAdelaar</span></div>
                        <div class="tv-manage-access-dialog__user-remove-column">
                           <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access">
                              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10">
                                 <g fill="none" stroke="#758696" stroke-width="2">
                                    <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path>
                                 </g>
                              </svg>
                           </div>
                        </div>
                     </div>
                     <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="ladedimone">
                        <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%28102,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3EL%3C/text%3E%3C/svg%3E"><span>ladedimone</span></div>
                        <div class="tv-manage-access-dialog__user-remove-column">
                           <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access">
                              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10">
                                 <g fill="none" stroke="#758696" stroke-width="2">
                                    <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path>
                                 </g>
                              </svg>
                           </div>
                        </div>
                     </div>
                     <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="DK32100">
                        <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%28339,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3ED%3C/text%3E%3C/svg%3E"><span>DK32100</span></div>
                        <div class="tv-manage-access-dialog__user-remove-column">
                           <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access">
                              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10">
                                 <g fill="none" stroke="#758696" stroke-width="2">
                                    <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path>
                                 </g>
                              </svg>
                           </div>
                        </div>
                     </div>
                     <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="Pisonglobal">
                        <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%28126,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3EP%3C/text%3E%3C/svg%3E"><span>Pisonglobal</span></div>
                        <div class="tv-manage-access-dialog__user-remove-column">
                           <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access">
                              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10">
                                 <g fill="none" stroke="#758696" stroke-width="2">
                                    <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path>
                                 </g>
                              </svg>
                           </div>
                        </div>
                     </div>
                     <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="whiteltr">
                        <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%2893,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3EW%3C/text%3E%3C/svg%3E"><span>whiteltr</span></div>
                        <div class="tv-manage-access-dialog__user-remove-column">
                           <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access">
                              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10">
                                 <g fill="none" stroke="#758696" stroke-width="2">
                                    <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path>
                                 </g>
                              </svg>
                           </div>
                        </div>
                     </div>
                     <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="nerf_herder">
                        <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="https://s3.tradingview.com/userpics/3591101-9n72.png"><span>nerf_herder</span></div>
                        <div class="tv-manage-access-dialog__user-remove-column">
                           <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access">
                              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10">
                                 <g fill="none" stroke="#758696" stroke-width="2">
                                    <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path>
                                 </g>
                              </svg>
                           </div>
                        </div>
                     </div>
                     <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="Swaine123">
                        <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="https://s3.tradingview.com/userpics/4117895-HxYz.png"><span>Swaine123</span></div>
                        <div class="tv-manage-access-dialog__user-remove-column">
                           <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access">
                              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10">
                                 <g fill="none" stroke="#758696" stroke-width="2">
                                    <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path>
                                 </g>
                              </svg>
                           </div>
                        </div>
                     </div>
                     <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="Astynaxe">
                        <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="https://s3.tradingview.com/userpics/4207689-Eli2.png"><span>Astynaxe</span></div>
                        <div class="tv-manage-access-dialog__user-remove-column">
                           <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access">
                              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10">
                                 <g fill="none" stroke="#758696" stroke-width="2">
                                    <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path>
                                 </g>
                              </svg>
                           </div>
                        </div>
                     </div>
                     <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="BassieWouters">
                        <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%28120,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3EB%3C/text%3E%3C/svg%3E"><span>BassieWouters</span></div>
                        <div class="tv-manage-access-dialog__user-remove-column">
                           <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access">
                              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10">
                                 <g fill="none" stroke="#758696" stroke-width="2">
                                    <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path>
                                 </g>
                              </svg>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
               <div class="sb-inner-shadow top i-invisible"></div>
               <div class="sb-inner-shadow"></div>
               <div class="sb-scrollbar-wrap">
                  <div class="sb-scrollbar sb-scrollbar-body ui-draggable ui-draggable-handle" style="height: 317.46px; top: 1px;"></div>
               </div>
            </div>
         </div>
      </div>
   </div>
   <div class="tv-dialog__close js-dialog__close">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 13 13" width="13" height="13">
         <path d="M5.182 6.596L1.293 2.707.586 2 2 .586l.707.707 3.889 3.889 3.889-3.889.707-.707L12.606 2l-.707.707L8.01 6.596l3.889 3.889.707.707-1.414 1.414-.707-.707L6.596 8.01l-3.889 3.889-.707.707-1.414-1.414.707-.707 3.889-3.889z"></path>
      </svg>
   </div>
</div>

FUNCTION 刪除用戶

def removeusers(self, unsubscribed, htmlsource): import re tv_users = [] names = BS(htmlsource, features="html.parser") result = names.find_all("div", {"class": "tv-manage-access-dialog__user-list-row"}) for res in result: #print(res) tv_users.append(res.text) #print(elem) tempsave = '/html/body/div[11]/div/div/div[2]/div/div[2]/div[2]/div[1]/div/div[1]/div[2]/div' #PARENT DIV TO ALL USERS'tv-manage-access-dialog__user-list-body js-user-list' tv_user_list = '/html/body/div[11]/div/div/div[2]/div/div[2]/div[2]/div[1]/div' print('working on arviman') #tempsave = '/html/body/div[11]/div/div/div[2]/div/div[2]/div[2]/div[1]/div/div[1]/div[2]/div' for user in result: if user.text in unsubscribed: elem = names.find(string=re.compile(user.text)) UNSUBSCRIBED_ROOT_XPATH = self.xpath_soup(elem) tostrip = '/div[1]/span' #GOES UP 2 ELEMENTS FROM SPAN NAME TO ROOT DIV OF USER. toappend = '/div[2]/div' # LOCATION OF BUTTON 'X' TO REMOVE USER if UNSUBSCRIBED_ROOT_XPATH.endswith(tostrip): UNSUBSCRIBED_ROOT_XPATH = UNSUBSCRIBED_ROOT_XPATH.replace(tostrip, '') UNSUBSCRIBEUSER_BTN = UNSUBSCRIBED_ROOT_XPATH + toappend self.driver.find_element(By.XPATH,UNSUBSCRIBEUSER_BTN).click() print(user.text, "REMOVED")

管理訪問彈出窗口 WINDOW - 列表

<div class="tv-dialog js-dialog tv-dialog--popup i-focused ui-draggable" tabindex="-1" style="width: calc(100% - 20px); max-width: 500px; top: 459px; left: 265px; z-index: 112;"> <div class="tv-dialog__section tv-dialog__section--title js-dialog__drag tv-dialog__grab ui-draggable-handle"> <div class="js-title-text tv-dialog__title">Manage Pine Script Access</div> </div> <div> <div> <div class="tv-dialog__section tv-manage-access-dialog__section js-search-placeholder"> <div class="tv-search-row"> <input class="tv-search-row__input js-input-control" type="text" name="q" value="" autocomplete="off" data-role="search" placeholder="Add user"> <span class="tv-search-row__input-reset i-hidden js-reset-button"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 95.939 95.939" width="95.939" height="95.939"> <path d="M62.82 47.97l32.53-32.534a2 2 0 0 0 0-2.828L83.332.586a2 2 0 0 0-2.827 0L47.97 33.12 15.435.587c-.75-.75-2.078-.75-2.828 0L.587 12.607a2 2 0 0 0 0 2.83L33.12 47.97.588 80.504a2 2 0 0 0 0 2.828l12.02 12.02a1.997 1.997 0 0 0 2.83 0L47.97 62.818l32.535 32.535a2 2 0 0 0 2.827 0l12.02-12.02c.78-.783.78-2.05 0-2.83L62.82 47.97z"></path> </svg> </span> <span class="tv-search-row__search-icon"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18 18" width="18px" height="18px"> <path fill-rule="evenodd" d="M12.5 11h-.79l-.28-.27A6.47 6.47 0 0 0 13 6.5 6.5 6.5 0 1 0 6.5 13c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L17.49 16l-4.99-5zm-6 0C4.01 11 2 8.99 2 6.5S4.01 2 6.5 2 11 4.01 11 6.5 8.99 11 6.5 11z"></path> </svg> </span> <div class="tv-username-hint-list js-hidden tv-username-hint-list--full-border" style="left: 0px; top: 100%; width: 65%; z-index: 100;"></div> </div> </div> <div class="tv-dialog__section tv-manage-access-dialog__section"> <div class="tv-text tv-manage-access-dialog__user-list-header js-user-list-header">14 users have access</div> <div class="tv-manage-access-dialog__user-list-container tv-dialog__scroll-wrap js-dialog__scroll-wrap wrapper-2KWBfDVB- sb-scroll-active" style=""> <div class="tv-dialog__scroll-wrap-inner js-user-list-attach" style="bottom: auto; top: 0px;"> <div class="tv-manage-access-dialog__user-list-body js-user-list"> <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="snub-fighter"> <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%2890,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3ES%3C/text%3E%3C/svg%3E"><span>snub-fighter</span></div> <div class="tv-manage-access-dialog__user-remove-column"> <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"> <g fill="none" stroke="#758696" stroke-width="2"> <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path> </g> </svg> </div> </div> </div> <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="KingThies_"> <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="https://s3.tradingview.com/userpics/1662357-tYZf.png"><span>KingThies_</span></div> <div class="tv-manage-access-dialog__user-remove-column"> <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"> <g fill="none" stroke="#758696" stroke-width="2"> <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path> </g> </svg> </div> </div> </div> <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="Eniesee_ldk"> <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%28312,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3EE%3C/text%3E%3C/svg%3E"><span>Eniesee_ldk</span></div> <div class="tv-manage-access-dialog__user-remove-column"> <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"> <g fill="none" stroke="#758696" stroke-width="2"> <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path> </g> </svg> </div> </div> </div> <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="sugarjun"> <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%289,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3ES%3C/text%3E%3C/svg%3E"><span>sugarjun</span></div> <div class="tv-manage-access-dialog__user-remove-column"> <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"> <g fill="none" stroke="#758696" stroke-width="2"> <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path> </g> </svg> </div> </div> </div> <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="dijkie"> <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%28144,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3ED%3C/text%3E%3C/svg%3E"><span>dijkie</span></div> <div class="tv-manage-access-dialog__user-remove-column"> <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"> <g fill="none" stroke="#758696" stroke-width="2"> <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path> </g> </svg> </div> </div> </div> <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="PaulAdelaar"> <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%2884,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3EP%3C/text%3E%3C/svg%3E"><span>PaulAdelaar</span></div> <div class="tv-manage-access-dialog__user-remove-column"> <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"> <g fill="none" stroke="#758696" stroke-width="2"> <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path> </g> </svg> </div> </div> </div> <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="ladedimone"> <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%28102,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3EL%3C/text%3E%3C/svg%3E"><span>ladedimone</span></div> <div class="tv-manage-access-dialog__user-remove-column"> <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"> <g fill="none" stroke="#758696" stroke-width="2"> <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path> </g> </svg> </div> </div> </div> <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="DK32100"> <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%28339,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3ED%3C/text%3E%3C/svg%3E"><span>DK32100</span></div> <div class="tv-manage-access-dialog__user-remove-column"> <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"> <g fill="none" stroke="#758696" stroke-width="2"> <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path> </g> </svg> </div> </div> </div> <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="Pisonglobal"> <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%28126,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3EP%3C/text%3E%3C/svg%3E"><span>Pisonglobal</span></div> <div class="tv-manage-access-dialog__user-remove-column"> <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"> <g fill="none" stroke="#758696" stroke-width="2"> <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path> </g> </svg> </div> </div> </div> <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="whiteltr"> <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%2893,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3EW%3C/text%3E%3C/svg%3E"><span>whiteltr</span></div> <div class="tv-manage-access-dialog__user-remove-column"> <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"> <g fill="none" stroke="#758696" stroke-width="2"> <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path> </g> </svg> </div> </div> </div> <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="nerf_herder"> <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="https://s3.tradingview.com/userpics/3591101-9n72.png"><span>nerf_herder</span></div> <div class="tv-manage-access-dialog__user-remove-column"> <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"> <g fill="none" stroke="#758696" stroke-width="2"> <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path> </g> </svg> </div> </div> </div> <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="Swaine123"> <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="https://s3.tradingview.com/userpics/4117895-HxYz.png"><span>Swaine123</span></div> <div class="tv-manage-access-dialog__user-remove-column"> <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"> <g fill="none" stroke="#758696" stroke-width="2"> <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path> </g> </svg> </div> </div> </div> <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="Astynaxe"> <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="https://s3.tradingview.com/userpics/4207689-Eli2.png"><span>Astynaxe</span></div> <div class="tv-manage-access-dialog__user-remove-column"> <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"> <g fill="none" stroke="#758696" stroke-width="2"> <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path> </g> </svg> </div> </div> </div> <div class="tv-manage-access-dialog__user-list-row js-user-row" data-username="BassieWouters"> <div class="tv-manage-access-dialog__user-info-column js-userlink-popup"><img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220,0,20,20%22%20width=%2239%22%20height=%2239%22%3E%3Crect%20height=%2220%22%20width=%2220%22%20fill=%22hsl%28120,25%25,50%25%29%22/%3E%3Ctext%20fill=%22white%22%20x=%2210%22%20y=%2214.8%22%20font-size=%2214%22%20font-family=%22Trebuchet%20MS,Arial,sans-serif%22%20text-anchor=%22middle%22%3EB%3C/text%3E%3C/svg%3E"><span>BassieWouters</span></div> <div class="tv-manage-access-dialog__user-remove-column"> <div class="apply-common-tooltip tv-manage-access-dialog__user-remove-btn js-user-remove-btn" title="Remove access"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"> <g fill="none" stroke="#758696" stroke-width="2"> <path d="M1.125 9.11L9.13 1.104M1.125 1.105L9.13 9.11"></path> </g> </svg> </div> </div> </div> </div> </div> <div class="sb-inner-shadow top i-invisible"></div> <div class="sb-inner-shadow"></div> <div class="sb-scrollbar-wrap"> <div class="sb-scrollbar sb-scrollbar-body ui-draggable ui-draggable-handle" style="height: 317.46px; top: 1px;"></div> </div> </div> </div> </div> </div> <div class="tv-dialog__close js-dialog__close"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 13 13" width="13" height="13"> <path d="M5.182 6.596L1.293 2.707.586 2 2.586l.707.707 3.889 3.889 3.889-3.889.707-.707L12.606 2l-.707.707L8.01 6.596l3.889 3.889.707.707-1.414 1.414-.707-.707L6.596 8.01l-3.889 3.889-.707.707-1.414-1.414.707-.707 3.889-3.889z"></path> </svg> </div> </div>

編輯

根據要求,我嘗試了這種改變。

 for user in result: if user.text in unsubscribed: self.driver.find_element_by_css_selector(f"[data-username='{user.text}'] svg").click() selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [data-username='snub-fighter'] svg

在此處輸入圖像描述

很奇怪,你在那里嘗試做什么。 嘗試一些簡單的東西,比如下面的代碼:

user_list = ['ladedimone', 'PaulAdelaar', 'Swaine123']

# you're on page with unsubscribe list using Selenium

for user in user_list:
    driver.find_element_by_css_selector(f"[data-username='{user}'] svg").click()

花了一段時間,但這是解決方案。

def removeusers(self, unsubscribed, htmlsource):
    #print("Missing users in Unsubscribed list:",unsubscribed)
    wait(self.driver, 6).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Manage Access']"))).click()
    time.sleep(3)
    for name in unsubscribed:
        #print( "//div[@data-username='{}']//div[contains(@class,'tv-manage-access-dialog__user-remove-btn')]".format(name))
        try:
            self.driver.find_element_by_xpath(
                "//div[@data-username='{}']//div[contains(@class,'tv-manage-access-dialog__user-remove-btn')]".format(
                    name)).click()
            print("REMOVED : ",name)

        except Exception as e:
            print(e)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM