0

I am working on scraping data from owler.com. I have to apply a filter using the advanced search option of the website

THis image

I'm trying to simulate the task using Selenium in Python but I'm unable to. Here is my code:

self.driver.find_element_by_id("advanced-search").click()

        self.driver.find_element_by_xpath('//*[@id="advanced-search-popup"]/div/div/div[2]/div[1]/div[2]/div[2]/div[1]/olr-select-box/div/div/div/select/option[101]').click()
        self.driver.find_element_by_xpath("//select[@name='labelName']/option[text()='India']").click()
        self.driver.find_element_by_id("advanced-search-results").click()
        `

But the above code results in an error

NoSuchElementException: Message: no such element: Unable to locate element:

Any suggestions or input to solve this issue? I also tried to execute JavaScript from Selenium to do the task but it isn't working either. Adding Screenshot of errors

enter image description here

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
akash dwivedi
  • 77
  • 1
  • 10
  • Have you tried waiting for a given page to load before executing the next element.click() call? It's likely that the element can't be located because the page hasn't completed loading. For a basic solution you could try time.sleep() for a few seconds, but Selenium also has [a more specialized solution for this problem](http://selenium-python.readthedocs.io/waits.html). – Zev Averbach May 28 '17 at 01:37
  • I am using this after page is fully loaded , already used time.sleep() function in script but isn't working though. – akash dwivedi May 28 '17 at 01:55
  • Can you provide the `page_source`? Difficult to diagnose otherwise. – Zev Averbach May 28 '17 at 02:13
  • go on owler.com and sign in . It's home page where advanced search is working. – akash dwivedi May 28 '17 at 02:17
  • it's getting the element but can't able to click the element. the error is shown only after clicking. – akash dwivedi May 28 '17 at 02:19
  • Are you sure? NoSuchElementException should not be caused by a click. Can you add debug output immediately before the click? In this way, if the exception is displayed before the debug output, you will know it is not the click. – Mikhail Ramendik May 28 '17 at 02:40
  • @MikhailRamendik Added screenshot of errors. – akash dwivedi May 28 '17 at 03:26
  • @ZevAverbach Any suggestions? – akash dwivedi May 28 '17 at 18:05
  • man even if you put a time.sleep() for load the page, some time you need put it again between a click and another because when you click on some element is called some functionality that it's not always quickly. just to try introduce a time.sleep(5) between each click and try it – Carlo 1585 May 29 '17 at 10:40
  • I haven't had a chance to log in, but seeing your stacktrace I'm wondering whether [this](https://stackoverflow.com/a/41744403/4386191) would help, since you're getting an "element not visible" error. – Zev Averbach May 29 '17 at 13:45

0 Answers0