0

I was making a bot with selenium but I can not click here: enter image description here

There are many classes and I can not find which one I should use , because I tried something but didn't do it.

For example, button name is OTURUM AÇ and I wrote like this , but it does not work.

browser = driver.find_elements_by_xpath('//button[text()="OTURUM AÇ"]').click()

Update from comments: https://dlive.tv/ I wanna log in there. But I can't.

DebanjanB
  • 118,661
  • 30
  • 168
  • 217

4 Answers4

0

This should work for you

btn = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//span[text()='OTURUM AÇ']")))
driver.execute_script('arguments[0].click();', btn)
0

It doesn't work because you are trying to find a button which has a text 'OTURUM AÇ' inside of it. In html which you add to question, there is no <button> tag so you need to search this element with <span>.

login = driver.find_element_by_xpath('//span[text()="OTURUM AÇ"]')
driver.execute_script('arguments[0].click();', login)

In html, it is not mandatory to use a <button> tag to place a button on page so make sure you check the tags.

0

You use wrong locator. There is login button with span tag, not button. Locotor will be:

//span[text()="OTURUM AÇ"]

But using text in locators is not good practice. You can rewrite it using css:

.sign-register-buttons .btnA span

or the same xpath locator:

//*[contains(@class, 'sign-register-buttons')]//*[contains(@class, 'btnA')]//span

They will work for any site language.

0

To click on the element with text as OTURUM AÇ you can use the following based Locator Strategies:

browser.find_element_by_xpath("//div[@class='sign-register-buttons flex-align-center']//span[text()='OTURUM AÇ']").click()

Ideally, to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='sign-register-buttons flex-align-center']//span[text()='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
DebanjanB
  • 118,661
  • 30
  • 168
  • 217