0

I am coding a bot for tinder with selenium but its not working. Here is my code.

fb_button = self.driver.find_element_by_xpath('//*[@id="content"]/div/div[1]/div/div/main/div/div[2]/div[2]/div/div/span/div[2]/button')
fb_button.click()

This code is for clicking the facebook login button. However when i run the code, it dont work healthy.I am getting an error like this.

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate e
lement: {"method":"xpath","selector":"//*[@id="content"]/div/div[1]/div/div/main/div/div[2]/div
[2]/div/div/span/div[2]/button"}

However when i try to create an object and try to call this function, it returns something.

HTML of the button:

<button type="button" class="button Lts($ls-s) Z(0) CenterAlign Mx(a) Cur(p) Tt(u) Bdrs(100px) Px(24px) Px(20px)--s Py(0) Mih(42px)--s Mih(50px)--ml button--outline Bdw(2px) Bds(s) Trsdu($fast) Bdc(#fff) C(#fff) Bdc(#fff):h C(#fff):h Bdc(#fff):f C(#fff):f Bdc(#fff):a C(#fff):a Fw($semibold) focus-button-style W(100%) Fz(4vw)--ms" draggable="false" aria-label="Facebook ile oturum aç"><span class="Pos(r) Z(1) D(ib)">Facebook ile oturum aç</span></button>
asked Feb 12, 2020 at 7:18
5
  • 1
    Please add the html of the button in the question Commented Feb 12, 2020 at 7:23
  • @SameerArora added. Commented Feb 12, 2020 at 7:25
  • 1
    add wait for getting element because sometimes page load then the element is present in HTML. Commented Feb 12, 2020 at 7:25
  • i added a 6 seconds sleep time before selecting the xpath but it isnt working. Commented Feb 12, 2020 at 7:28
  • 1
    check your XPath correctly because it gives NoSuchElementException. Commented Feb 12, 2020 at 7:34

2 Answers 2

2

you can wait until the element can clickable and present in HTML dom.

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
fb_button = WebDriverWait(driver, 10).until(
 EC.element_to_be_clickable((By.XPATH, "your_xpath")))
fb_button.click()

you can check the wait conditions here!

answered Feb 12, 2020 at 7:31
Sign up to request clarification or add additional context in comments.

Comments

2

You can click on the element using xpath:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Facebook ile oturum aç']"))).click()

Note: You have to add the following imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
answered Feb 12, 2020 at 7:30

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.