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
themmfa
5471 gold badge5 silver badges21 bronze badges
-
1Please add the html of the button in the questionSameer Arora– Sameer Arora2020年02月12日 07:23:29 +00:00Commented Feb 12, 2020 at 7:23
-
@SameerArora added.themmfa– themmfa2020年02月12日 07:25:10 +00:00Commented Feb 12, 2020 at 7:25
-
1add wait for getting element because sometimes page load then the element is present in HTML.Manali Kagathara– Manali Kagathara2020年02月12日 07:25:50 +00:00Commented Feb 12, 2020 at 7:25
-
i added a 6 seconds sleep time before selecting the xpath but it isnt working.themmfa– themmfa2020年02月12日 07:28:13 +00:00Commented Feb 12, 2020 at 7:28
-
1check your XPath correctly because it gives NoSuchElementException.Manali Kagathara– Manali Kagathara2020年02月12日 07:34:06 +00:00Commented Feb 12, 2020 at 7:34
2 Answers 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
Manali Kagathara
7615 silver badges11 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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
Sameer Arora
4,5073 gold badges12 silver badges20 bronze badges
Comments
lang-py