Answer the question
In order to leave comments, you need to log in
Why is Selenium not finding the button?
When a request is made for a discord invite link and it turns out that the link is already outdated, selenium correctly finds the "Go to Discord" button:
button = driver.find_element_by_css_selector("[type='button']")
<button type="button" class="marginTop40-i-78cZ button-3k0cO7 button-38aScr lookFilled-1Gx00P colorBrand-3pXr91 sizeLarge-1vSeWK fullWidth-1orjjo grow-q77ONN"><div class="contents-18-Yxp">Accept Invite</div></button>
<button type="button" class="marginTop40-i-78cZ button-3k0cO7 button-38aScr lookFilled-1Gx00P colorBrand-3pXr91 sizeLarge-1vSeWK fullWidth-1orjjo grow-q77ONN"><div class="contents-18-Yxp">Continue to Discord</div></button>
Answer the question
In order to leave comments, you need to log in
standard search approach by button tact - xpath (there are also alternatives, for example, protractor)
text = 'Continue to Discord'
text = 'Принять приглашение'
driver.find_element_by_xpath('//button/div[contains(text(), "{}")]'.format(text))
{"method":"xpath","selector":"//button/div[contains(text(), "Принять приглашение")]"}
from cyrtranslit import to_latin
from selenium import webdriver
from selenium.webdriver.firefox.webdriver import WebDriver
def waittest:
def __init__(self, selector, value):
self.selector = selector
self.value = value
def __call__(self, driver):
element = driver.find_element_by_css_selector(self.selector)
text = element.text
print('checking text: "{}" against "{}"'.format(to_latin(text, 'ru'), self.value))
if to_latin(text, 'ru') == self.value:
return element
else:
return None
text = to_latin('Принять приглашение', 'ru')
element = WebDriverWait(driver, 10).until( waittest("button[class *= 'button']", text))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question