2
driver = webdriver.Remote(service.service_url)
timeout = 50
driver.get("https://www.nseindia.com/option-chain")
selection = Select(driver.find_element_by_id('select_symbol'))
time.sleep(2)
selection.select_by_index(3)
time.sleep(2)
driver.quit()

I need to get the call option total from the table on the site for each option in the dropdown menu, but the selected option doesn't load and the table doesn't load. Pls help

2
  • I don't think so it would be easy to do that since the app has implemented ways to check if the user is hitting using some automated softwares. After a couple of tries you will start getting 403 errors. Commented Sep 2, 2021 at 4:44
  • @demouser123 : There's always a workaround in computer science. Commented Sep 2, 2021 at 5:30

2 Answers 2

1

Sometimes, Webapps do not show desired web element while handled by automation software/tool such as Selenium.

The workaround I have come to know know is that, in this kind of situation, we need to pass Arrow_down key using automated software and using JS (could be Select class also depends on the website), we can let the application show all the options.

Using Selenium this is how drop down looks :- (Basically it does not show the options).

enter image description here

Now when we use the below code that has Arrow down keys implemented :

Code :-

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome(driver_path)
driver.maximize_window()
#driver.implicitly_wait(50)
driver.get("https://www.nseindia.com/option-chain")
wait = WebDriverWait(driver, 20)

select = Select(wait.until(EC.presence_of_element_located((By.ID, "equity_optionchain_select"))))
select.select_by_visible_text("NIFTY")

ActionChains(driver).key_down(Keys.ARROW_DOWN).key_up(Keys.ARROW_UP).perform()
driver.execute_script("return document.getElementById('select_symbol').selectedIndex = '3';")

Using Selenium this is how it looks now :

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

how about using

driver.find_element_by_xpath('//*[@id="select_symbol"]/option[3]').click()

It is easy to only change option['number'].

1 Comment

The issue here is that, he is not able to see drop down menu using Selenium.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.