Reputation: 11
i wanna load with a selenium python bot periodically new messages of a website. the messages come in div's with innerText.
here is the part of my skript checking with xPath:
`
try:
while True:
messages = driver.find_elements(By.XPATH, "//div[contains(@class, 'text-message')]")
for message in messages:
print(message.text)
time.sleep(5)
except KeyboardInterrupt: print("Stopped by user") `
in the console i can test the xpath and it returns an array of div's with all messages.
i tried so many stuff but cant get the messages. ChatGPT is also no help at all.
anyone can help me?
Thanks!!
changing the xPath, searching by class, using an observer, ExpectedConditions, ...
Upvotes: 0
Views: 72
Reputation: 1577
Probabily Selenium is seeing a different page for some reason.
I would try to check what it's seeing with a screenshot
from selenium import webdriver
from PIL import Image
driver = webdriver.Chrome(executable_path = ‘path\to\chromedriver.exe’’)
url = "my_website_url"’
driver.get(url)
driver.save_screenshot(‘ss.png’)
screenshot = Image.open(‘ss.png’)
screenshot.show()
Maybe it's blocked by some security features and/or you're on another tab/page
Upvotes: 0