i had problem with selenium x path i make Facebook sharing script but he is not clicking share button? i'm using python

0 votes

I had a problem with Facebook share button when I execute that it's doing all good but it's not clicking on facebook share button please help me!

Here is my video you can see here>> https://photos.app.goo.gl/Pi1tRQTwhqg5tmpn9

here is element HTML code:

here is this element code : 

   <span class="_18vi"><a class=" _2nj7 _18vj _18vk" data-ft="{ &quot;tn&quot;: &quot;J&quot;, &quot;type&quot;: 25 }" href="/ajax/sharer/?s=22&amp;appid=25554907596&amp;id=1816791348467451&amp;p[0]=130584170421519&amp;p[1]=1816792805133972&amp;sharer_type=all_modes&amp;av=130584170421519" rel="dialog" role="button" tabindex="0" title="Send this to friends or post it on your timeline.">Share</a></span>

Here is my code:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.keys import Keys
    import time
    
    
    driver = webdriver.Chrome()
    driver.get("https://www.facebook.com/")
    driver.maximize_window()
    phone=WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='email']"))).send_keys("03460522942")
    time.sleep(2)
    pas=WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='pass']"))).send_keys("......")
    time.sleep(.5)
    login=WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='loginbutton']"))).click()
    time.sleep(.5)
    #Searc
    search=WebDriverWait(driver, 100).until(EC.element_to_be_clickable((By.XPATH, "/html[1]/body[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/form[1]/div[1]/div[1]/div[1]/div[1]/input[2]"))).send_keys("lunch.pk")
    search2=WebDriverWait( driver, 100).until(EC.element_to_be_clickable((By.XPATH, "/html[1]/body[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/form[1]/button[1]"))).click()
    click_page=WebDriverWait( driver, 50).until(EC.element_to_be_clickable((By.XPATH, "/html[1]/body[1]/div[1]/div[3]/div[1]/div[1]/div[3]/div[2]/div[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/a[1]/span[1]"))).click()
    click_photos=WebDriverWait( driver, 50).until(EC.element_to_be_clickable((By.XPATH, "/html[1]/body[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[3]"))).click()
    click_banner=WebDriverWait( driver, 50).until(EC.element_to_be_clickable((By.XPATH, "/html[1]/body[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[2]/div[2]/div[1]/div[2]/div[1]/div[2]/div[1]/div[2]/div[1]/div[1]/a[1]/img[1]"))).click()
    click_Share=WebDriverWait( driver, 50).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='u_1b_2']/div[2]/div/div[2]/div/span[3]/a/text()"))).click()


Here is my error:

    Traceback (most recent call last):
      File ".\facebook.py", line 24, in <module>
        click_Share=WebDriverWait( driver, 50).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='u_1b_2']/div[2]/div/div[2]/div/span[3]/a/text()"))).click()
      File "C:\Users\Hamza Lachi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\support\wait.py", line 71, in until
        value = method(self._driver)
      File "C:\Users\Hamza Lachi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 297, in __call__
        element = visibility_of_element_located(self.locator)(driver)
      File "C:\Users\Hamza Lachi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 128, in __call__
        return _element_if_visible(_find_element(driver, self.locator))
      File "C:\Users\Hamza Lachi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 148, in _element_if_visible

    AttributeError: 'NoneType' object has no attribute 'is_displayed'

Iמ

    return element if element.is_displayed() == visibility else False
Jul 24 in Python by Hamza Lachi
217 views

1 answer to this question.

0 votes
Hey Hazma, I tried running your code, but instead of using Absolute Xpath, I tried using Relative Xpath which comes very handy and can be captured by using ChroPath (Chrome extension to get Xpath).

I am able to automate your task by using element ids and relative Xpaths. I hope you could also do the same.
answered Jul 26 by Abha
• 27,180 points
yes I also tired I think it's facebook errors

Related Questions In Python

0 votes
1 answer

Python `if x is not None` or `if not x is None`?

There's no performance difference, as they compile ...READ MORE

answered Sep 3, 2018 in Python by Priyaj
• 56,920 points
244 views
0 votes
1 answer

Make a unix alias with python script

The scope of an alias command is the shell ...READ MORE

answered Sep 10, 2018 in Python by Priyaj
• 56,920 points
39 views
0 votes
1 answer

Make a unix alias with python script

The scope of an alias command is the shell ...READ MORE

answered Sep 20, 2018 in Python by Priyaj
• 56,920 points
396 views
0 votes
1 answer

How do I generate some random numbers with a distribution using Python?

scipy.stats.rv_discrete is what you ned IMHO. You can supply ...READ MORE

answered Oct 31, 2018 in Python by Anirudh
• 2,070 points

edited Dec 14, 2018 by Anirudh 142 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,110 points
977 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,132 views
+1 vote
2 answers

How to automate image upload from my computer to site using python-selenium?

Hey, this code worked for me: image_path=os.path.abspath('.\\folder1\\subfolder2\file1.jpg') driver.find_element_by_id("Id of ...READ MORE

answered Aug 19 in Python by Rishi
62 views
0 votes
2 answers

What is the difference between python lists and arrays?

Python arrays and lists have the same ...READ MORE

answered Jun 10 in Python by Nisa
• 1,090 points
59 views