pip install -U marigoso

"""
Explanation: Using marigoso to Post a Comment to a Blogger Post
A simple tutorial demonstrating how to use marigoso to automatically launch a browser and post a comment to a blog post. 
Install marigoso
Execute the command below to install marigoso.
End of explanation
"""


from marigoso import Test
browser = Test().launch_browser("Firefox")

"""
Explanation: Launch the browser
We can use marigoso Test to launch a browser.
End of explanation
"""


browser.get_url("http://pytestuk.blogspot.co.uk/2015/11/testing.html")

"""
Explanation: Navigate
Once the browser is launched it will display a blank page. We then instruct this browser to navigate to the blog post.
End of explanation
"""


browser.press_available("id=cookieChoiceDismiss")

"""
Explanation: Accept Google's Cookie Policy
Once the browser has visited Blogger, it may or may not display the Cookie Policy of Google. We then use the "press_available" function of the browser to accept that policy if it is available.
End of explanation
"""


iframe = browser.get_element("css=div#bc_0_0T_box iframe")
browser.switch_to.frame(iframe)

"""
Explanation: Switch to iFrame
The comment section or comment form of the post is inside an iframe. In order for us to be able to interact with the comment form, we need to use the Selenium function called "switch_to.frame". First we obtain the iframe and then switch into it.
End of explanation
"""


browser.kb_type("id=commentBodyField", "An example of Selenium automation in Python.")

"""
Explanation: Keyboard Type
After switching to the comment iframe, we can finally interact with the comment form. We grab the comment field and enter anything we would like to say. Here we are simulating the action of typing something in the keyboard to enter into the comment form.
End of explanation
"""


browser.select_text("id=identityMenu", "Google Account")

"""
Explanation: Select an Item from a Dropdown Menu
We then simulate mouse movement for selecting an item in a dropdown menu. You will not see any actual mouse movement in this case however, because we will just grab the dropdown and instruct it to select the item we want.
End of explanation
"""


browser.submit_btn("Publish")

"""
Explanation: After simulating the keyboard typing and dropdown selection, the page should now look like the image below:

Submit the Form
Finally, we submit the form by using the "submit_btn" function, which will simulate pressing the "Publish" button in the page.
End of explanation
"""


browser.quit()

"""
Explanation: After clicking the "Publish" button, the page will then be redirected to the Google Sign-in page. What goes beyond here is now an exercise for the reader. Please try it on your own. Write the next code that will automatically log you to your Google Account.

Disposing the browser
Once your finished, you can quit the the browser using the command below.
End of explanation
"""


