Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98827

Python - Selenium Unable to locate element on Search button

$
0
0

I'm trying to locate and click on a button "Search" on internal website using python selenium. The element with class = "button":

<a href="javascript:showSearch(true)" title="Search" class="button" id="button_search">
    <img src="images/icon_search.gif" alt="">Search
  </a>

When click, this button will show a table containing many search filters, and the class changes to "button_active"

<a href="javascript:showSearch(true)" title="Search" class="button_active" id="button_search">
    <img src="images/icon_search.gif" alt="">Search
  </a>

And xpath is:

//*[@id="button_search"]

locate the css

Packages:

import selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

I've tried all the following code:

search_button = driver.find_element_by_id('button_search')
or 
search_button = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="button_search"]')))
or
search_button = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@title="Search" and @class="button" and @id="button_search"]')))

and many way by ID, LINK_TEXT.... but I always get the same error that:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="button_search"]"}
  (Session info: chrome=79.0.3945.79)

Do you have any ideas why it may not be able to locate this button? Thank you!

Edit: I've tried switch_to.frame and it works! Thank you all!


Viewing all articles
Browse latest Browse all 98827

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>