Desconozco el motivo, pero me ha pasado de no poder identificar un elemento, y en general lo resolví cambiando la manera de detectarlo (ej. en vez de hacerlo por XPATH, podés probar hacerlo por el nombre de la class).
Si es un botón, igualmente debería tener un button tag, que sería el que deberías seleccionar realmente, con lo cual te diría revises el HTML a ver si efectivamente existe.
Absolute XPath has a big disadvantage: If the DOM of the page is changed the path of the element changes which leads the XPath to error out. So it’s always recommended to use relative XPath.
You want to write an XPath for the ‘Add to Cart’ button.
On inspecting the element ’ Add to Cart’ I get the following element
<input id="add-to-cart-button" name="submit.add-to-cart" title="Add to Shopping Cart" data-hover="Select <b>__dims__</b> from the left<br> to add to Shopping Cart" class="a-button-input" type="submit" value="Add to Cart" aria-labelledby="submit.add-to-cart-announce" data-ol-has-click-handler="">
I notice the text ‘Add to Cart’ is uniquely identifying the element so I can construct my XPath using the value attribute.
XPath :
//input[@value = 'Add to Cart']
OR
You can use the attribute ‘title’ for this case since its unique :
//input[@title = 'Add to Shopping Cart']
Can you provide the button element after inspecting it?
A button should have a unique id. Or you can also search by the visible text.
I have tried several methods with XPATH and is not working. The element is detected but, I can’t make click on it:
For example I used the next methods without any success:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,"//button[@value='1'][@id='u_0_c']"))).click()
or this one:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,"//*[@id="u_0_6"]"))).click()
I have tried your code and I got the next error in the compiler:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,‘//*[@id=“u_0_6”]’))).click()
File “D:\Instalables\Python38-32\lib\site-packages\selenium\webdriver\remote\webelement.py”, line 80, in click
self._execute(Command.CLICK_ELEMENT)
File “D:\Instalables\Python38-32\lib\site-packages\selenium\webdriver\remote\webelement.py”, line 633, in _execute
return self._parent.execute(command, params)
File “D:\Instalables\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 321, in execute
self.error_handler.check_response(response)
File “D:\Instalables\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py”, line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element Aceptar todas is not clickable at point (522, 502). Other element would receive the click: Aceptar todas</butt
on> (Session info: chrome=87.0.4280.141)
Then I have tried the next code and nothing happens. The previous error is gone, but it is not able to make click on the button to accept the cookies.
element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="u_0_6"]')))
driver.execute_script("arguments[0].click();", element)
You need to check where exactly the element you are trying to click present. If the button is present on a different iframe you first need to switch to the window and then try clicking the button.