Friday 15 March 2013

Python and Selenium: What's a good way to access links hidden in dropdown menus built by Javascript? -


I am creating a webcrawler in Python using selenium. Below is the job that searches for links that works fine, except for the part that has been commented. It is the idea that is being investigated to hover over each link to the page, and reveals that over the looming action links (for example in the dropdown menu made with JavaScript), then those links Add to getLinksFromHTML (recursive call) Add "If the code! = 1" is the only part that is to ensure that there is only one recursive call there).

However, I also tested a new link does not take when I page recursive call JS links within the dropdown menu (I'm looking at page). All the visual link has been lifted upright

Can I do that Selenium sees those dropdown links? I need a general solution, that is, there is no specific page-specific element in a particular element ID or code. Thanks for reading!

  def getLinksFromHTML (currUrl, code): ListlinkerHref = Braujhrkfind_element_bai_kpas ( "// * [@ href]") links1 = [] links2 = [] to link ListlinkerHref: Url = Link.get_attribute ("href") #hov = ActionChains (Browser) Move_to_element (link) #hov.perform () #if code! = 1: # links1 = self.getLinksFromHTML (currUrl, 1) if the url link in 1: links2.append (url) Return link 1 + Links 2    

the reason turns out it was not working that I have Firefox apparently was using Firefox driver, move_to_element not really hover over elements It just focuses on it. When I switched to a chrome driver, it actually kept on menu items and showed the submenu. (Note that there are some errors in the actual function, but this is not the issue of this question.)

TL; DR: If you are using Selenium Vebdrivr and you want to hover over links to such material appears submenu, use Chrome and Firefox do.

No comments:

Post a Comment