Most modern website have dynamic elements where a click event makes an AJAX call and replaces all or usually part of a webpage. The response can be tracked using the network tab in Developer tools
How do you do this in Selenium?
In python I thought about grabbing the element text again after the click but it’s not updating
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
ChromeDriverPath64 = "D:/Software/chromedriver_126-win64/chromedriver.exe"
options = webdriver.ChromeOptions()
s = Service(executable_path="D:/Software/chromedriver_126-win64/chromedriver.exe")
options.page_load_strategy = 'normal'
options.binary_location = "C:/Program Files/Google/Chrome/Application/chrome.exe"
try:
driver = webdriver.Chrome(service=s, options=options)
driver.get("https://example.com/")
MyClasss = driver.find_elements(By.CLASS_NAME, "MyClass")
for el in MyClasss:
elTxt = el.text
if "wanted" in elTxt.lower():
el.click()
MyClass = driver.find_elements(By.CLASS_NAME, "MyClass")
for el1 in MyClass:
el1Txt = el1.text
if "wanted" in el1Txt.lower():
print(el1Txt)
driver.quit()
except Exception as e:
print(e)
There is a lot of conflicting information on how to get AJAX request with Selenium from what I’ve tried most seems outdated
2