0

this is the HTML code:

 </template>
                            </el-table-column>
                            <el-table-column prop="announcementTitle" label="公告标题">
                                <template slot-scope="scope">
                                <span class="ahover">
                                    <a v-html="scope.row.announcementTitle" target="_blank" :href="linkLastPage(scope.row)"></a>
                                    <span v-show="checkDocType(scope.row.adjunctType)" class="icon-f"><i class="iconfont" :class="[checkDocType(scope.row.adjunctType)]"></i></span>
                                </span>
                                </template>

If I want to get the content of annoncementTitle with Python + selenium and css_selector, how should I write the code?

Steven
  • 24,410
  • 42
  • 108
  • 130

2 Answers2

0

Identify the element using following css_selector and then use get_attribute("attribute_name") to get the atrribute value.

print(driver.find_element(By.CSS_SELECTOR , 'el-table-column[prop="announcementTitle"]').get_attribute("label"))

you might need some wait to avoid the synchronization issue.

KunduK
  • 32,888
  • 5
  • 17
  • 41
0

To print the value of the <label> attribute i.e. 公告标题 you need to use get_attribute() method and you can use the following css_selector based locator strategy:

from selenium.webdriver.common.by import By

print(driver.find_element(By.CSS_SELECTOR , 'el-table-column[prop=announcementTitle]').get_attribute("label"))

Ideally you need to induce WebDriverWait for the visibility_of_element_located() and you can use the following locator strategy:

print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "el-table-column[prop='announcementTitle']"))).get_attribute("label"))

Note : You have to add the following imports :

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

You can find a relevant discussion in Python Selenium - get href value

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352