微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

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”请帮我解决

解决方法

嗯,这完全是鼠标悬停,首先是 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()='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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。