第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Webelement內(nèi)的xpath查找硒

Webelement內(nèi)的xpath查找硒

喵喵時光機 2021-03-30 13:10:50
我有此頁面:<html><head>    <title>Document Example</title></head><body>    <div id="container">        <div class="section">            <h1>Section 1</h1>            <li class="links">                <ul><a href="link.com/1"></a></ul>                <ul><a href="link.com/2"></a></ul>                <ul><a href="link.com/3"></a></ul>            </li>        </div>        <div class="section">            <h1>Section 2</h1>            <li class="links">                <ul><a href="link.com/4"></a></ul>                <ul><a href="link.com/5"></a></ul>                <ul><a href="link.com/6"></a></ul>            </li>        </div>        <div class="section">            <h1>Section 3</h1>            <li class="links">                <ul><a href="link.com/7"></a></ul>                <ul><a href="link.com/8"></a></ul>                <ul><a href="link.com/9"></a></ul>            </li>        </div>    </div></body></html>我想要按部分分組鏈接:driver.get("mypage.com")sections = driver.find_elements_by_xpath("//div[@class='section']")for section in sections:    section_name = section.find_element_by_xpath("//h1[@class='name']").get_attribute('innerHTML') #This fails    links = section.find_elements_by_xpath("//ul/a") #This find all links in page, not only links in section問題是,我通過xpath找到了所有頁面中的元素列表(WebElement),現(xiàn)在我想通過xpath查找元素部分而不是所有頁面中的所有特定元素。怎么了?編輯1這樣可以解決問題(現(xiàn)在是xpath啟動白點。):driver.get(“ mypage.com”)sections = driver.find_elements_by_xpath("//div[@class='section']")for section in sections:    section_name = section.find_element_by_xpath(".//h1[@class='name']").get_attribute('innerHTML') #This fails    links = section.find_elements_by_xpath(".//ul/a") #This find all links in page, not only links in section在這里可以找到以下解釋:http : //selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.find_element_by_xpath
查看完整描述

2 回答

?
莫回?zé)o

TA貢獻1865條經(jīng)驗 獲得超7個贊

可能會工作


sections = driver.find_elements_by_xpath("//div[@class='section']")

for i, section in enumerate(sections):

    section_name = section.text

    links = section.find_elements_by_xpath("//div[@class='section'][%s]//a" % str(i+1))


查看完整回答
反對 回復(fù) 2021-04-13
?
神不在的星期二

TA貢獻1963條經(jīng)驗 獲得超6個贊

這是你想要的?您可以嘗試以下方法:

//*[@id="container"]/div/h1/following-sibling::li/ul


查看完整回答
反對 回復(fù) 2021-04-13
  • 2 回答
  • 0 關(guān)注
  • 207 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號