0

I am trying to get the values of available license inside the table using selenium in python3. I am able to get the values using XPATH, and iterate through each rows. But XPATH is not ideal, since the table might change and include an additional column, thus will fail to get the correct value.

The values I want, is 98,50,etc...

<div class="slick-cell l6 r6 licensesUsedValueGrid">
 <div class="slick-cell odd" style="padding: 0px;width:100%;height: 44px;">
   <div style="padding: 15% 4px 0px 0%;float: right;">98</div>
 </div>
</div>

<div class="slick-cell l6 r6 licensesUsedValueGrid">
 <div class="slick-cell odd" style="padding: 0px;width:100%;height: 44px;">
  <div style="padding: 15% 4px 0px 0%;float: right;">50</div>
 </div>
</div>

This is using XPATH, and it worked:

for i in range(1, rows, 2):

    pak_id = browser.find_element_by_xpath(f'//*[@id="scrollBarDiv"]/div/div[{i}]/div[3]/div/div/div[1]').text

    used_license = browser.find_element_by_xpath(f'//*[@id="scrollBarDiv"]/div/div[{i}]/div[7]/div/div').text
    available_license = browser.find_element_by_xpath(f'//*[@id="scrollBarDiv"]/div/div[{i}]/div[8]/div/div').text

I would like to use class name or some other means so that even if they add another column to the table, i will be able to capture the right value of 'license used' and 'license available'

Picture of how it looks like on chrome:

https://i.stack.imgur.com/bM30C.png

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

2 Answers2

0

Probably just:

browser.find_elements_by_css_selector('.licensesUsedValueGrid')
pguardiario
  • 53,827
  • 19
  • 119
  • 159
  • How about `div.licensesUsedValueGrid div[style$='right;']` so that he can retrieve the values too? – supputuri Jan 09 '20 at 01:01
  • I am using to iterate through the rows. So, I need something that will iterate through the rows and get the value inside "Used' and Available' even if the column gets shifted. – Checksum321 Jan 15 '20 at 21:41
  • You would do `for div in browser.find_elements_by_css_selector('.licensesUsedValueGrid')` – pguardiario Jan 15 '20 at 23:37
0

To extract all the values of available licenses using Selenium and Python you have to induce WebDriverWait for the visibility_of_all_elements_located() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    print([my_elem.text for my_elem in WebDriverWait(driver, 5).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "div.licensesUsedValueGrid>div.slick-cell.odd>div")))])
    
  • Using XPATH:

    print([my_elem.text for my_elem in WebDriverWait(driver, 5).until(EC.visibility_of_all_elements_located((By.XPATH, "//div[contains(@class, 'licensesUsedValueGrid')]/div[@class='slick-cell odd']/div")))])
    
  • 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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you, but that is not the issue. I can get the values on each rows. The issue is when the table changes to include an additional column, then the results get shifted to the right – Checksum321 Jan 15 '20 at 21:39