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, 2019 in Python by Hamza Lachi
2,855 views

1 answer to this question.

+1 vote
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, 2019 by Abha
• 28,140 points
yes I also tired I think it's facebook errors

Related Questions In Python

0 votes
1 answer

i write this python to read dataset into panda data frame but im getting NameError: name 'true' is not defined. Below is the code:

change  def parse(path):   g = gz ...READ MORE

answered Mar 15, 2020 in Python by Abhishek Shingadiya
3,659 views
0 votes
0 answers

I am trying to click the button but it is not working and it is drop list ..

<a class="quickreports btn btn3d tbbtn" href="javascript:" style="position:static" ...READ MORE

Dec 2, 2019 in Python by anonymous
• 120 points
796 views
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
• 58,020 points
2,652 views
0 votes
2 answers

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,500 points
13,674 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,143 views
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,910 points
7,221 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, 2019 in Python by Rishi
6,232 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 11, 2019 in Python by Nisa
• 1,090 points
1,546 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP