Yasaswini Gedela
Yasaswini Gedela

Reputation: 1

How do i select element in a list present in an un-ordered list using selenium python

this the website I am dealing with https://www.bseindia.com/corporates/ann.html?curpg=1&annflag=1&dt=20211021&dur=P&dtto=20211027&cat=Insider%20Trading%20/%20SAST&scrip=&anntype=A Here I am able to send the code for the "security name" but in-order to submit it I need to click the dropdown element that comes after giving the security name. How do I achieve this with selenium. I used the code below and its not working(StaleElementReferenceException)

security_name = driver.find_element_by_id("scripsearchtxtbx")
security_name.send_keys('INE350H01032')
sec_click = driver.find_element_by_xpath('//*[@id="ulSearchQuote2"]/li')
sec_click.click()

Upvotes: 0

Views: 107

Answers (2)

Rhayma Mohamed
Rhayma Mohamed

Reputation: 1

you can paly with Xpath:

security_name = driver.find_element_by_id("scripsearchtxtbx")
security_name.send_keys('INE350H01032')
sec_click = driver.find_element_by_xpath("//ul[@id='ulSearchQuote2']/li//strong[text()='INE350H01032']")
sec_click.click()
same -->("//ul[@id='ulSearchQuote2']//strong[text()='INE350H01032']")

you can check more about xpath here: xpath

Upvotes: 0

Luke Hamilton
Luke Hamilton

Reputation: 727

This can also be accomplished using the Keys Library within Selenium. Selenium Keys not only sends input statements like strings, but it can also send commands such as escape, tab, or in this case enter. Your updated code should look as follows:

security_name = driver.find_element_by_id("scripsearchtxtbx")
security_name.send_keys('INE350H01032')
security_name.send_keys(Keys.ENTER)
sec_click = driver.find_element_by_xpath('//*[@id="ulSearchQuote2"]/li')
sec_click.click()

These are called special keys. For more examples and more information on this, see this link

Upvotes: 2

Related Questions