4

I am trying to select the radio button "Hitter". Could anyone help? I've tried a lot of different things, but keep getting "Message: element not visible".

Thanks!

enter image description here

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Josh
  • 107
  • 2
  • 11
  • Could it be your element is outside the selenium window? (can be solved by `driver.maximize_window()` before you `.get` the page). Another reason could be you're trying to grab the element before it is loaded, quick workaround for that is to add a `time.sleep(5)` (or any suitable timespan) before you try to find the element. – jaapvee May 12 '15 at 08:00
  • @jaapvee trying `maximize_window()` makes total sense and can help, but adding a wait would not help I am afraid. Selenium finds an element, but cannot click it, since it is invisible. – alecxe May 12 '15 at 08:19
  • @alecxe, yeah I think you're right. Let's see when the OP reacts: if the `maximize_window` does the trick, the kuddo's for the right answer go to you :) – jaapvee May 12 '15 at 09:09
  • Thanks for your guys' response. maximize window didn't work :( I did some research into the error thrown. "ElementNotVisibleException" which says that "the element is present in the DOM, but not visible, so unable to interact with". Here is something similar on stackoverflow, but I am having trouble understand its solution: http://stackoverflow.com/questions/27927964/selenium-element-not-visible-exception – Josh May 12 '15 at 16:04

1 Answers1

7

There are multiple ways to locate the radio input, here is the one using find_element_by_id():

radio = driver.find_element_by_id("ContentPlaceHolder1_HitterRadioButton")
radio.click()

Or, if you have problems with this approach, you can simulate a click via javascript:

radio = driver.find_element_by_id("ContentPlaceHolder1_HitterRadioButton")
driver.execute_script("arguments[0].click();", radio)
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Thank you for the response. However, after running it, I am still getting the same "Message: element no visible" error : ( – Josh May 12 '15 at 06:47
  • Weird however, because when I check if radio.is_selected(), it is able to tell that the radio button is selected.... But when I try to click it while not selected, it can't seem to fine the radio button at all "Message: element not visible" – Josh May 12 '15 at 07:03
  • if possible can you provide the URL to provide a solution for this? – Shaik May 12 '15 at 07:40
  • @Josh also, check if there are no other elements with the same id attribute value. – alecxe May 12 '15 at 08:20
  • The page would require you have an free account to the webpage. The home webpage is baseballmonster.com and if you end up making an account, I am looking at https://baseballmonster.com/Daily.aspx – Josh May 12 '15 at 16:05
  • Ahh your second idea worked! That was what I was leaning towards. Thanks. Final question. After I have clicked "Pitchers" the page is refreshed with everything being the same but the table it contains. I then want to click on the same element "Export to excel" as I had on the previous page "Hitters". However, I am receiving a "StaleElementReference: element is not attached to the page document". I know this is because The page refreshed, and as have the elements. I read that I must "discard" the previous reference to that element "Export to Excel" and select it again. How do I discard? – Josh May 12 '15 at 16:43
  • @Josh good. Regarding your question - you just need to refind the element, find the element once again. – alecxe May 12 '15 at 21:46