1

I use python3.6 and selenium3.6 to test charts from www.tradingview.com under Safari 11.When I want to zoom out the chart by clicking an invisible element before hovering the mouse on it.

driver.get('https://www.tradingview.com/chart/f8my3Ybg/')
zoom_out_button = driver.find_elements_by_class_name('zoom-out-right-button-control-bar')
Time.sleep(500)
ActionChains(driver).move_to_element(zoom_out_button).click().perform()

It comes out an error message

an element command could not be completed because the element is not visible on the page

I search the web and cannot find a way to correct it.The following is the code I analyzed.How would I realize such action on an invisible element? the HTML code I analyzed 1

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
C HAN
  • 49
  • 4
  • I'm seeing lots of popups appearing on this page as an unregistered user. those are blocking me from being able to try our your code. Are you interacting with this page as a registered user so that you don't get those popups? – Breaks Software Nov 21 '17 at 12:57
  • as a registered user, popups also come out but not frequently. I still have some problem to dealing with popups,due to I prevent me from screen capture. – C HAN Nov 21 '17 at 19:26

1 Answers1

0

Instead of :

ActionChains(driver).move_to_element(zoom_out_button).click().perform()

First try to hover as follows :

ActionChains(driver).move_to_element(zoom_out_button).click("xpath_css_hidden_element").perform()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you for your help and I tried ActionChains(driver).move_to_element(zoom_out_button).build().perform(),then got a error message showed that "ActionChains(driver).move_to_element(zoom_out_button).build().perform() AttributeError: 'ActionChains' object has no attribute 'build' – C HAN Nov 21 '17 at 13:43
  • ActionChains(driver).move_to_element(zoom_out_button).perform() print("TIMEER 50S!") time.sleep(50) ActionChains(driver).click(zoom_out_button) – C HAN Nov 21 '17 at 13:45
  • Updated my answer. Let me know the Status. – undetected Selenium Nov 21 '17 at 13:51
  • ActionChains(driver).move_to_element(zoom_out_button).\ click("/html/body/div[1]/div[1]/div/div[2]/div[2]/div/svg[2]").perform() I am confused about your statement click("xpath_css_hidden_element") and I just replace it with xpath which I got from Safari.Failed with a message "AttributeError: 'str' object has no attribute 'id' and I had tried to get element by xpath like this zoom_out_button_xpath = driver.find_element_by_xpath("/html/body/div[1]/div[1]/div/div[2]/div[2]/div/svg[2]") but also failed. I am sorry I am a greenhorn. – C HAN Nov 21 '17 at 14:26
  • To deal with `svg` elements follow this [Selenium WebDriver Java: How to Click on elements within an SVG using XPath](https://stackoverflow.com/questions/41829000/selenium-webdriver-java-how-to-click-on-elements-within-an-svg-using-xpath) – undetected Selenium Nov 21 '17 at 14:28
  • It seems a little complexity for me. I will try to understand how to deal with xpath and try it again. Thank you. – C HAN Nov 21 '17 at 14:40
  • It is a question about xpath with svg or a question about converting invisible element to visible? – C HAN Nov 21 '17 at 15:12
  • See your `xpath` which contains **`svg‌​[2]`**. For `svg` you need to construct `xpath` carefully. – undetected Selenium Nov 21 '17 at 15:14
  • svgPath = "//div[@class='control-bar control-bar--hidden']/*[name()='svg'][2]/*[name()='path']" zoom_out_button = driver.find_element_by_class_name('zoom-out-right-button-control-bar') zoom_out_button_xpath = driver.find_element_by_xpath(svgPath) ActionChains(driver).click(svgPath).perform() but an error comes upAttributeError: 'str' object has no attribute 'id' I think my xpath is right. – C HAN Nov 21 '17 at 18:49
  • @CHAN Now apply this `xpath` in the solution I provided & update me the result – undetected Selenium Nov 21 '17 at 18:52
  • It really happened, and I got what I want. ActionChains(driver).move_to_element(zoom_out_button_xpath).click(zoom_out_button_xpath).perform() Thank you DebanjanB, your post really helpful. – C HAN Nov 21 '17 at 19:16
  • It is really helpful.I click the "this answer is helpful" button on your answer.I am new to stackoverflow, I think your answer will help others. – C HAN Nov 21 '17 at 19:31
  • I tested the script just now and fount it did not show zooming out result before which I want.It seems that the code can pass but without click.Is it related to the invisible element ? – C HAN Nov 22 '17 at 01:58
  • @CHAN Add some wait to the Action Chain – undetected Selenium Nov 22 '17 at 02:44
  • for i in range(5): ActionChains(driver).move_to_element(zoom_out_button_xpath).click(zoom_out_button_xpath).perform() print(i) #print("TIMEER 50S!") #time.sleep(50) WebDriverWait(driver, 120).until(EC.presence_of_element_located((By.LINK_TEXT, "Market Closed"))) I plan to add above code to my script after the script finish. I hope it works.It took too long to browser and take screenshot of 900+ tickers – C HAN Nov 22 '17 at 07:30
  • And I found some part of my screenshot did not change.I do not find reason until now. – C HAN Nov 22 '17 at 07:31
  • I have add some wait before click action but still no reaction. – C HAN Nov 23 '17 at 08:05