【问题标题】:Need Xpath or anything to identify the elements unique for using selenium需要 Xpath 或任何东西来识别使用 selenium 的独特元素
【发布时间】:2021-09-30 14:58:08
【问题描述】:

1)电子档:

<mat-list-item class="mat-list-item ng-star-inserted" style="">
   <div class="mat-list-item-content">
       <div class="mat-list-item-ripple mat-ripple" mat-ripple=""></div>
       <div class="mat-list-text"></div>
       <a class="loggedInListItem mat-list-item" mat-list-item="" tabindex="0">
           <div class="mat-list-item-content">
               <div class="mat-list-item-ripple mat-ripple" mat-ripple=""></div>
               <div class="mat-list-text"></div>e-File <!---->
               <mat-icon class="mat-icon notranslate material-icons mat-icon-no-color ng-star-inserted" role="img" aria-hidden="true">expand_less</mat-icon>
           </div>
       </a>
   </div>
</mat-list-item>

2) 所得税申报表

<mat-list-item class="mat-list-item ng-star-inserted" style=""><div class="mat-list-item-content"><div class="mat-list-item-ripple mat-ripple" mat-ripple=""></div><div class="mat-list-text"></div><a class="loggedInListItem mat-list-item" mat-list-item="" tabindex="0"><div class="mat-list-item-content"><div class="mat-list-item-ripple mat-ripple" mat-ripple=""></div><div class="mat-list-text"></div>Income Tax Returns <!----><mat-icon class="mat-icon notranslate material-icons mat-icon-no-color ng-star-inserted" role="img" aria-hidden="true">expand_less</mat-icon></div></a></div></mat-list-item>
  1. 表格 26
<mat-list-item class="mat-list-item ng-star-inserted" style=""><div class="mat-list-item-content"><div class="mat-list-item-ripple mat-ripple" mat-ripple=""></div><div class="mat-list-text"></div><a class="loggedInListItem mat-list-item" mat-list-item="" tabindex="0"><div class="mat-list-item-content"><div class="mat-list-item-ripple mat-ripple" mat-ripple=""></div><div class="mat-list-text"></div>View Form 26AS <!----></div></a></div></mat-list-item>

我想在子菜单中选择表格 26,当我将鼠标光标保持在“电子文件”上时,它会在那些我的光标应该移动到“所得税申报表”上的选项中显示选项,并在我应该单击的选项中显示选项选择“form 26”请帮我解决一下

【问题讨论】:

标签: python selenium selenium-webdriver ui-automation


【解决方案1】:

嗯,这都是鼠标悬停,首先是e-file,然后是income tax returns,最后是form 26。所以基本上我们需要 ActionsChain 来鼠标悬停:-

示例代码:

wait = WebDriverWait(driver, 10)
ActionChains(driver).move_to_element(wait.until(EC.element_to_be_clickable((By.XPATH, "(//mat-icon[contains(text(), 'expand_more')])[3]/..")))).move_to_element(wait.until(EC.visibility_of_element_located((By.XPATH, "//span[text()='Income Tax Returns ']/..")))).perform()
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()='View Form 26AS']/.."))).click()

进口:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

更新 1:

wait = WebDriverWait(driver, 10)
e_file = wait.until(EC.element_to_be_clickable((By.XPATH, "//span[contains(text(),' Dashboard')]/../following-sibling::a")))
action = ActionChains(driver)
action.move_to_element(e_file).perform()
action.move_to_element(wait.until(EC.visibility_of_element_located((By.XPATH, "//span[text()='Income Tax Returns ']/..")))).perform()
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()='View Form 26AS']/.."))).click()

【讨论】:

    【解决方案2】:

    你能试试下面的代码吗,

    user_id = driver.find_element_by_id("panAdhaarUserId")user_id.send_keys("UserName")
    
    continue_button= driver.find_element_by_class_name("large-buttonprimary")continue_button.click()
    
    wait3=WebDriverWait(driver,10)element5=wait3.until(EC.element_to_be_clickable((By.XPATH,"//div[@class='mat-checkbox-inner-container']")))
    
    element5.click()
    
    
    wait = WebDriverWait(driver,10)element = wait.until(EC.visibility_of_element_located((By.ID,'loginPasswordField'))
    element.send_keys("Password")
    
    wait2 = WebDriverWait(driver,10)element4= wait.until(EC.element_to_be_clickable((By.CLASS_NAME,"large-button-primary")))
    element4.click()
    
    action = ActionChains(driver)
    element1=driver.find_element_by_xpath("((//a[@id='navBar'])[1])")
    element2=driver.find_element_by_xpath("((//div[@id='cdk-overlay-4']//child::div//child::div//child::button)[1])")
    
    element3=driver.find_element_by_xpath
    ("//span[contains(text(),'File Income Tax Return')]")
    
    action.move_to_element(element1)
    .move_to_element(element2).move_to_element(element3).perform()
    

    进口

    from selenium import  webdriver
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.support.wait import WebDriverWait
    

    【讨论】:

      猜你喜欢
      • 2014-11-27
      • 1970-01-01
      • 2016-10-26
      • 1970-01-01
      • 2020-06-20
      • 2016-01-15
      • 2021-08-28
      • 1970-01-01
      • 2018-03-18
      相关资源
      最近更新 更多