需要Xpath或任何东西来标识使用selenium所特有的元素

2024-10-01 09:18:30 发布

您现在位置:Python中文网/ 问答频道 /正文

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,当我将鼠标光标停留在“电子文件”上时,它会显示我的光标应移到“所得税申报表”上的选项,并显示我应单击并选择“表格26”的选项请帮助我解决问题


Tags: textdivstylecontentitemnglistclass
2条回答

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

示例代码:

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

相关问题 更多 >