I want to click on a button element which is identical to another button element on the same page but one is in the front and one is at the back(see pic). how can I do this? the first x button's html code is like:
<div id="ModalPopAmityHostel" class="modal fade in" role="dialog" aria-hidden="false" style="display: block;">
<div class="modal-dialog " style="z-index:104546464; ">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Amity Hostel</h4>
</div>
second x button's html code is:
<div id="StudentSatisfactionPop" class="modal fade in" role="dialog" aria-hidden="false" style="display: block; padding-right: 15px;">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">STUDENT SATISFACTION SURVEY </h4>
</div>
this is my code using selenium in python:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
chromedriver = "/usr/share/chromedriver/chromedriver"
driver = webdriver.Chrome(chromedriver)
driver.maximize_window()
#wait = WebDriverWait(driver, 1)
driver.get("https://student.amizone.net")
# 3 | type | name=_UserName | 7071804 |
driver.find_element(By.NAME, "_UserName").send_keys("username")
# 4 | type | name=_Password | 62ae6f |
driver.find_element(By.NAME, "_Password").send_keys("password")
# 9 | click | css=#loginform .login100-form-btn | |
driver.find_element(By.CSS_SELECTOR, "#loginform .login100-form-btn").click()
driver.implicitly_wait(10)
driver.find_element(By.CLASS_NAME, "close").click()
it gives this error:
Traceback (most recent call last):
File "amizone_automated_login.py", line 36, in <module>
driver.find_element(By.CLASS_NAME, "close").click()
File "/home/manik/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "/home/manik/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/home/manik/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/manik/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=79.0.3945.88)
I think the error is coming because it's clicking the x button behind the pop-up because it comes first in the html script. is there a way of clicking the x button in the front?