Hi I am trying to click on a button within a pop up("klant aanpassen"), I already tried allot of options including ActionChains
but I just don't get it to work. Right now this is my script:
driver.find_element_by_xpath('//*[@title="Acties"]').click()
time.sleep(2)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[class='_2f9OE _2nG1g yG7LA mekFH _2zshv _2enAb _2g-UE iyvDv _17-jo']"))).click()
The first code does the right thing, open up the UI(PopUp)
The second line of code give's me the following error:
Warning (from warnings module):
File "C:/Users/Marnix Bolier/Desktop/TLinputter.py", line 52
driver.find_element_by_xpath('//*[@title="Acties"]').click()
DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
Traceback (most recent call last):
File "C:/Users/Marnix Bolier/Desktop/TLinputter.py", line 54, in <module>
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[class='_2f9OE _2nG1g yG7LA mekFH _2zshv _2enAb _2g-UE iyvDv _17-jo']"))).click()
File "C:\Users\Marnix Bolier\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\support\wait.py", line 89, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
I also tried the following line:
driver.find_element_by_xpath("//button[@class='_2f9OE _2nG1g yG7LA mekFH _2zshv _2enAb _2g-UE iyvDv _17-jo']").click()
That gives the following error:
line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
Google Inspector (button highlighted in blue):
Can anyone tell me what I am doing wrong here, Thanks.
CodePudding user response:
Locators like this CSS Selector button[class='_2f9OE _2nG1g yG7LA mekFH _2zshv _2enAb _2g-UE iyvDv _17-jo']
are problematic since they based on too much class names. These class names may be dynamically changing per session and per page state.
This locator can also be not unique.
What we can try here is text based XPath like this:
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[contains(.,'Klant aanpassen')]"))).click()
This locator looks more stable and unique.