Home > Back-end >  Python Selenium how to interact with a specific button on a web page
Python Selenium how to interact with a specific button on a web page

Time:10-18

Hi i'm trying to interact with this web element in the following link https://www.gurufocus.com/stocks

Here you can find the image

I want to set it to 100 so that i can visualize 100 stocks at the time i've tried to interact with it by using the following code

wd.find_element_by_xpath("/html/body/div[1]/div/div/div[1]/section[2]/main/div/div[1]/div[3]/div[1]/span/div[2]").click()

wd.find_element_by_xpath("/html/body/div[2]/div[6]").click()

But only the first line works the second line gives me the following error

    selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='el-popover-2775']"}
  (Session info: chrome=106.0.5249.119)

It is not able to locate it i have also tried with the method find element_by_id but still not able to locate the button that sets the number on 100 This one does anyone has an other solution? Thanks in advance let me know if you need more information i will answer as soon as possible.

CodePudding user response:

you can select the dropdown like this:

from selenium.webdriver.common.by import By
driver.find_element(By.CLASS_NAME, "aio-tabs-button").click()

and select 100 like this:

driver.find_element(By.XPATH, "//div[@class='item' and contains(text(), '100')]").click()

However, I'd recommend using the API and a package like requests instead of simulating the browser.

  • Related