html - XPath element not Found - Stack Overflow

Following is the code to access element using Xpath on the Website (;expiry=2025-03-20 )Using XPATH, I

Following is the code to access element using Xpath on the Website (;expiry=2025-03-20 )

Using XPATH, I can reach the DIV which inherits the footer element. I can print content of that DIV element, but I receive error "Element not found" when trying to access footer using div/footer

from selenium import webdriver
import chromedriver_binary
from selenium.webdrivermon.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import time

chrome_options = Options()
chrome_options.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"  #     Verify this path!

chrome_options.add_experimental_option("prefs", {
"download.default_directory": r"C:\Users\Admin\Downloads",  # Set your download folder
"download.prompt_for_download": False,
"safebrowsing.enabled": True
})

driver = webdriver.Chrome(options=chrome_options)
try:
    url = ";expiry=2025-03-20"
    driver.get(url)
    time.sleep(5)  # Allow time for the page to load
    settings_button =     driver.find_element(By.XPATH,"/html/body/div[1]/div/div[2]/div[2]/div/div")
    print(settings_button.text)
    time.sleep(4)
    print("✅ Download initiated!")
    time.sleep(10)
finally:
    driver.quit()

Following is the code to access element using Xpath on the Website (https://web.sensibull/option-chain?tradingsymbol=NIFTY&expiry=2025-03-20 )

Using XPATH, I can reach the DIV which inherits the footer element. I can print content of that DIV element, but I receive error "Element not found" when trying to access footer using div/footer

from selenium import webdriver
import chromedriver_binary
from selenium.webdrivermon.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import time

chrome_options = Options()
chrome_options.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"  #     Verify this path!

chrome_options.add_experimental_option("prefs", {
"download.default_directory": r"C:\Users\Admin\Downloads",  # Set your download folder
"download.prompt_for_download": False,
"safebrowsing.enabled": True
})

driver = webdriver.Chrome(options=chrome_options)
try:
    url = "https://web.sensibull/option-chain?tradingsymbol=NIFTY&expiry=2025-03-20"
    driver.get(url)
    time.sleep(5)  # Allow time for the page to load
    settings_button =     driver.find_element(By.XPATH,"/html/body/div[1]/div/div[2]/div[2]/div/div")
    print(settings_button.text)
    time.sleep(4)
    print("✅ Download initiated!")
    time.sleep(10)
finally:
    driver.quit()
Share Improve this question asked Mar 20 at 10:42 pratik jamalepratik jamale 1 2
  • The Python code is not related to the problem and might be removed from this post. It's only about the xpath expression. – Bouke Commented Mar 20 at 11:53
  • @Bouke No, the code (a minimal reproducible example) is needed here because it may not be the XPath but instead some other issue and we won't be able to figure that out without it. – JeffC Commented Mar 20 at 17:18
Add a comment  | 

1 Answer 1

Reset to default 0

The Settings button can be selected by the following xpath expression:

//button[text()='Settings']

It is not required to use the complete path, using // will do here, meaning it will look everywhere in the DOM.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744415412a4573093.html

相关推荐

  • html - XPath element not Found - Stack Overflow

    Following is the code to access element using Xpath on the Website (;expiry=2025-03-20 )Using XPATH, I

    6天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信