0

I try to make some automations using Python+selenium (new to this). Unfortunatelly, inspecting elements of a specific webpage is more than hard. There is no id to use and I try xpath. I want to select a drop down list , i inspect this element and I copy the xpath which is //*[@id="frmMain:criteria:purchase_criteria_tab"]/div[13]/div[1]/div/button

my code is:

    NEXT_BUTTON_XPATH = "//*[@id='frmMain:criteria:purchase_criteria_tab']/div[13]/div[1]/div/button"
wait = WebDriverWait(driver, 10)
condition = expected_conditions.presence_of_element_located(
    (By.XPATH, NEXT_BUTTON_XPATH))
button = wait.until(condition)
button.click()

and I cannot get the element Any ideas? Thank you in advance.

2 Answers 2

1

try this

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait 
try:
    # for click element element_to_be_clickable condition used
    button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable(By.XPATH, "elemnt_xpath"))) 
    button.click()

except Exception as e:
    print(e)
Sign up to request clarification or add additional context in comments.

8 Comments

thank you. it returned a new error , Other element would receive the click: <span class="ui-button-text ui-c">...</span>
edit your question and add the URL which you are trying to scrape.
it's not a public URL
the syntax is correct for getting element.try to inspect element by right-clicking and copy XPath of element.
thats what i do, i already wrote it above, but it returns Other element would receive the click: <span class="ui-button-text ui-c">...</span>
|
0

You can click on the element using the syntax:

WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//*[@id='frmMain:criteria:purchase_criteria_tab']/div[13]/div[1]/div/button"))).click()

Note: You have to add the following imports:

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

2 Comments

thank you , i missed last import. syntax is ok now but element is not found :/
@gplati that is another question, please check your xpath for that and post that as a new question if still not solved

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.