I need to extract some values from a website, and to do so, I have to click on a button on that page. However, there seems to be an issue. I noticed that when I hit F12, I can identify the specific tag, class, XPath, and so forth, but when I use "CTRL+U" and attempt to find that button, it's not visible. I'm not sure why this happens, but okay.
This is the website:
https://www.b3.com.br/pt_br/produtos-e-servicos/negociacao/renda-variavel/empresas-listadas.htm
When I execute the following code:
driver.find_element(By.XPATH, '/html/body/app-root/app-companies-home/div/div/div/div/div[1]/div[2]/div/app-companies-home -filter-name/form/div/div[4]/button').click()
Essentially, I'm trying to simulate a click on the button labeled "TODOS", whose tag is:
<button type="submit" aria-label="Buscar Todas" class="btn btn-light btn-block mt-3">Todos</button>
and the FULL XPATH path is:
/html/body/app-root/app-companies-home/div/div/div/div/div[1]/div[2]/div/app-companies-home-filter-name/form/div/div[4]/button
However, I receive this error message:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/app-root/app-companies-home/div/div/div/div/div[1]/div[2]/div/app-companies-home-filter-name/form/div/div[4]/button"}
It seems that the HTML element isn't being found, despite its visibility when pressing F12. Any advice on how to resolve this issue?
This is my full code:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--remote-debugging-port=9222")
driver = webdriver.Chrome(service=None, options=chrome_options)
driver.get(
"https://www.b3.com.br/pt_br/produtos-e-servicos/negociacao/renda-variavel/empresas-listadas.htm"
)
time.sleep(5)
driver.find_element(
By.XPATH,
"/html/body/app-root/app-companies-home/div/div/div/div/div[1]/div[2]/div/app-companies-home-filter-name/form/div/div[4]/button",
).click()
I tried to use other ways to use find_element()
but without success