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
1 Answer
Reset to default 0The 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
评论列表(0条)