-1

I was having trouble with find elements by XPATH for a selenium script in Python.

Couldn’t understand the problem, i want to identify all of the elements that satisfy my xpath criteria.

So I simply compared the find_elements(By.XPATG, ‘//div’) to the same result when looking at Chrome’s Inspect tool.

The tool says 300+ results for this whereas my programme, which I got to return a count of results, only states 60? Any ideas? looks to be an thing from the browser/site side rather than my code.

Thanks

EDIT added my code:

import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
import login

print(time.time())

driver.get("WEBSITE URL")
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//body")))
time.sleep(1)
links = driver.find_elements(By.XPATH,'//body')
linklist = len(links)
print(linklist)

This provides a result of around 60 however when '//body' is put in the inspect element tool, it returns 300+

Apologies but the targeted webpage is confidential so I can't post. But suggestions are appreciated so I can investigate.

rev7777
  • 11
  • 2

1 Answers1

0

Does your web page has a scroll? If yes, you may need to deal with scroll bar. Also try different conditions for WebDriverWait, for example EC.visibility_of_all_elements_located or EC.presence_of_all_elements_located

frianH
  • 7,295
  • 6
  • 20
  • 45
kadis
  • 181
  • 6
  • It does have a scroll but the elements are all visible in the initial window and loaded. I can see the element as the script is running but the script can't... strange – rev7777 Jan 09 '23 at 11:12
  • Found the issue... I needed to switch iFrame – rev7777 Jan 09 '23 at 13:46