Facebook Wall posts - Auto reply - Python Selenium - python

I've been trying to create a Python Selenium script to reply to facebook wall posts.
I'll be naive in describing the problem since I'm learning both python, selenium and HTML as a beginner.
I'm not able to find a clickable element in my wall and click on the element. When I do manually click, there is a JS element which seems to create an editable element where I can write my comment as reply.
But finding the element to click is really tricky. Any help would be appreciated.
Here is the code snippet I've used.
mydriver.get(baseurl)
mydriver.maximize_window()
mydriver.find_element_by_xpath(xpaths['usernameTxtBox']).clear()
mydriver.find_element_by_xpath(xpaths['usernameTxtBox']).send_keys(username)
mydriver.find_element_by_xpath(xpaths['passwordTxtBox']).clear()
mydriver.find_element_by_xpath(xpaths['passwordTxtBox']).send_keys(password)
mydriver.find_element_by_xpath(xpaths['submitButton']).click()
post_box = mydriver.find_element_by_css_selector(".UFIAddCommentInput")
ActionChains(mydriver).move_to_element(post_box).click().perform()
print("InputContainer Selected")
post_box=mydriver.find_element_by_xpath("//*[#class='_1mf _1mj']")
post_box.send_keys("Testing using Name not ID. Selenium is easy.")
post_box.send_keys(Keys.ENTER)
print ("Posted...")
Here is where I'm trying to register the comment.
http://prntscr.com/bsxmsm
Thanks in advance.

Related

Selenium find a element with no class, div, text (Python)

I want to make a automatic google login with selenium but i cannot find the elements, the buttoenter image description heren "Next", because the class
is modified each time when we come to start a browser with selenium, or when we reset the login page and does not have Id, but the button is in a div that includes just this button,
I would like someone to help me find a solution to find how I can use this button in order to click it to skip the page where you have to put your email address to skip to the password
i would like to use css selector
(Google Chrome the browser I use)
I code with Selenium 4.2.0 on Linux Unbuntu
driver.find_element(By.CSS_SELECTOR, 'button[class="VfPpkd-LgbsSe VfPpkd-LgbsSe-OWXEXe-k8QpJ VfPpkd-LgbsSe-OWXEXe-dgl2Hf nCP5yc AjY5Oe DuMIQc LQeN7 qIypjc TrZEUc lw1w4b"]').click()
That will click the 'Next' button on Google login. Good luck getting any further though. Google seems to block logging in on Chromium.
You can either use jsname as an alternative for finding the element
I found a similar question here How can I inspect element in to div with jsname?
I think the person is doing pretty same thing
Hope this helps :)

id of xpath is getting changed every time in selenium python 2.7 chrome

one more problem i hv,i asked similar question earlier and i tried that method but not able use that methon in this problem so pls help me. it's element
html code is - FiltersĀ 
So basically, question is that there is one button its kind of toggle button and i want click on that button to select device like Desktop, Tablet & Mobile all check boxes are already (default) selected now i have to uncheck or deselect device, to do this, first i have to click on that toggle button , when i click on toggle button its id (gwt-uid-598) 598 is getting changed every time or every refresh. Can you pls help me, what should or which method should i follow in this case.
i am using below python code.
Click on device Filters
elem = driver.find_element_by_xpath('//*[#id="gwt-uid-598"]/div/div/span')
elem.click()
Thanks in advance.
Good question.
Try to use another selector, for example: css class or use xpath method contains().
Example: //div[contains(text(), "checkbox")]
I can help you if you can provide source code of the page or needed element.

How Do I Use Selenium WebDriver To Click A Non Anchor Tag?

I am using Selenium WebDriver to do automated testing of a website. I have been successful in clicking through numerous menus and links to a point.
At one point the website I am working with generates links that look like this:
<U onclick="HourglassSubmitItem(document.all('PageName').value, '00000001Responsibility Code')">Responsibility Code</U>
I am trying to use the .click functionality of the webdriver to click this link with no success.
Using this:
page.find_element_by_xpath("//u[contains(text(),'Responsibility Code')]")
successfully finds the U tag above. but when I add .click() to the end of this xpath, the click is not performed. But it also does not generate an error. So, my question is can Selenium be used to simulate clicks on an HTML tag that is NOT an anchor () tag? If so, how?
I will also say that I do not have control over the page I am working with, so changing the to is not possible.
I would appreciate any guidance the Community could provide.
Thank You for you help,
Chris
Sometimes using JavaScript could solve the "clicking" issue:
element = page.find_element_by_xpath("//u[contains(text(),'Responsibility Code')]")
page.execute_script('arguments[0].click();', element)
You can prefer JavaScript in this case.
WebElment element = page.find_element_by_xpath("//u[contains(text(),'Responsibility Code')]")
JavaScriptExecutor executor = (JavaScriptExecutor)driver;
executor.ExecuteScript("arguments[0].click();", element);

Trying to locate an href that contains text

I am very new to coding - We are using Selenium with python scripting.
Please find the attached screen shot for the HMTL of my page.
The actual web page is a table that has "x" for all the user accounts.
I am trying to locate the href attribute that contains a user account that I pass as variable.(In the below example I am trying to click on the link that has "expample#exampleemail.com" )
Can someone please help me locating the element.
Thanks!
You can find the element by xpath:
text = "example#example.com"
element = driver.find_element_by_xpath('//a[contains(#href, "%s")]' % text)
I've answered a similar question here...
In your case, just translate the java to python.
driver.find_element_by_css_selector("a[href*='example#example.com']")

How to select radio button using selenium

I am trying to click this radio button using selenium and python.
<input type="radio" name="tweet_target_1" value="website" class="tweet-website-button radio-selection-validate serialize-me newline-before field-order-15">
I have
website = driver.find_element(name="tweet_target_1")
website.click()
but it's not allowing me to click it. How can I click using a combo of name, value or class, value etc.?
Is there a good source of info about how to use selenium? Because most of what I've found is on java and I'm using python.
EDIT: using XPATH
I tried
website = driver.find_elements(By.XPATH, "//form[#id='dmca_form' and #class='twitter-form custom-form']/div[20][#class='list-container']/div[1][#class='list-item']/div[7][#class='clearfix inf-tweet init-hide']/div[#class='input']/ul[#class='options']/li[2]/label/input[#class='tweet-website-button radio-selection-validate serialize-me newline-before field-order-15']/")
website.click()
I keep getting
AttributeError: 'list' object has no attribute 'click'
I know this comes a little too late perhaps, but I joined just recently.
Tip: Use, Firebug and with it Firepath. Locate the radio button and find out the xpath for the element in question.
website = driver.find_element_by_xpath(".//**")
website.click()
OR
website = driver.find_element_by_xpath(".//**").click()
This should work all the time you try. Also, just using from selenium import webdriver
should make the click() function work correctly.
I'm not sure where you found the documentation that said you could call find_element like that, but you should either be doing driver.find_element_by_name("tweet_target_1") or driver.find_element(By.NAME, "tweet_target_1") (having first imported By of course). Also, Selenium Java code is pretty easily convertible to Python code; it follows a few pretty simple transformation rules, and if you still have questions, all the code for the library itself will also be on your machine to look at.

Categories

Resources