-1

What can I use to address v-if, css selector or xpath?

div class="el-table-box" v-if="!specialAnnounce">
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Steven
  • 24,410
  • 42
  • 108
  • 130
  • 2
    How can someone with your rep ask a question like this? Did you even search stackoverflow before asking? – BernardV Jun 07 '23 at 06:40
  • How can I write the code? content1=wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".el-table-box[v-if='!specialAnnounce']"))), it doesn't work – Steven Jun 07 '23 at 08:13
  • Try changing your xpath expression to `div[class="el-table-box"][v-if="!specialAnnounce"]`. – Jack Fleeting Jun 07 '23 at 12:15
  • Cell In[1], line 25 parent_div = wait.until(EC.visibility_of_all_elements_located(By.XPATH, "div[class="el-table-box"][v-if="!specialAnnounce"]")) ^ SyntaxError: invalid syntax. Perhaps you forgot a comma? – Steven Jun 07 '23 at 12:24

2 Answers2

0

Given the HTML:

<div class="el-table-box" v-if="!specialAnnounce">

You can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    element = driver.find_element(By.CSS_SELECTOR, "div.el-table-box[v-if$='specialAnnounce']")
    
  • Using XPATH:

    element = driver.find_element(By.XPATH, "//div[@class='el-table-box' and contains(@v-if, 'specialAnnounce')]")
    
  • Note : You have to add the following imports :

    from selenium.webdriver.common.by import By
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • --- TypeError Traceback (most recent call last) Cell In[2], line 21 19 # Wait for the announcement elements to be visible 20 wait = WebDriverWait(driver, 10) # Adjust the timeout value as needed ---> 21 announcement_elements = wait.until(EC.visibility_of_all_elements_located(By.CSS_SELECTOR, "div.el-table-box[v-if$='specialAnnounce']")) 22 # Extract the latest announcements within 2 hours 23 latest_announcements = [] TypeError: visibility_of_all_elements_located() takes 1 positional argument but 2 were given – Steven Jun 07 '23 at 08:50
0

Check the below code, using ExplicitWait and CSS locator:

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

wait = WebDriverWait(driver, 20)
announcement_elements = wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "div.el-table-box[v-if$='specialAnnounce']")))
Shawn
  • 4,064
  • 2
  • 11
  • 23
  • TimeoutException Traceback (most recent call last) Cell In[2], line 21 19 # Wait for the announcement elements to be visible 20 wait = WebDriverWait(driver, 10) # Adjust the timeout value as needed ---> 21 announcement_elements = wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "div.el-table-box[v-if$='!specialAnnounce']"))) 22 # Extract the latest announcements within 2 hours 23 latest_announcements = [] – Steven Jun 07 '23 at 12:43
  • Do you see any presence of an ` – Shawn Jun 07 '23 at 13:10
  • Follow the trouble shooting steps from this answer - https://stackoverflow.com/a/75865161/7598774 – Shawn Jun 07 '23 at 13:12