需要 Xpath 或任何东西来识别使用硒的独特元素

Need Xpath or anything to identify the elements unique for using selenium

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)所得税returns

<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>

我想 select 在子菜单中形成 26,当我将鼠标光标保持在“电子文件”上时,它会显示我的光标应移至“所得税 returns 和它显示了我应该单击的那些选项中的选项,select“表格 26”请帮我解决问题

好吧,这都是鼠标悬停,首先是 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()

你能试试下面的代码吗,

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