1

I´m trying to find a text box with Python and Selenium.. I Tried by_css_selector, bY XPATH, by ID, by name but the message is always the same:

Unable to locate element: #x-auto-225-input

this is the piece of html. I Want to find the textbox to fill it.

<td class="x-table-layout-cell" role="presentation" style="padding: 2px;">
    <div role="presentation" class=" x-form-field-wrap  x-component" id="x-auto-225" style="width: 150px;"></div>
    <input type="text" class=" x-form-field x-form-text " id="x-auto-225-input" name="PURCHASE_ORDER_CODE_NAME" tabindex="0" style="width: 150px;">
</td>

My last attempt was:

pc = browser.find_element_by_css_selector("#x-auto-225-input").click()
pc.send_keys("7555425-1")
5
  • 1
    can you please provide the html of your page Commented Mar 28, 2019 at 13:35
  • have you tried find_element_by_name("PURCHASE_ORDER_CODE_NAME") Commented Mar 28, 2019 at 13:38
  • if possible can provide the link of your web page? Commented Mar 28, 2019 at 13:40
  • Welcome to SO. Use the Expected condition and wait for the element to be visible before performing the operation. I don't see any issue with the locator or the code. Commented Mar 28, 2019 at 13:58
  • Is this element in an IFRAME? Have you tried a wait? Commented Mar 28, 2019 at 14:57

3 Answers 3

1

Looking at the html, id mentioned can be dynamic, so you can't put the static id in your identifier.
However, as name attribute is present in the html, you can use that to identify your element, like:

browser.find_element_by_name("PURCHASE_ORDER_CODE_NAME").click()

Updated answer as per discussion with the OP

As an iframe is present on the UI, you need to first switch to the iframe and then click on the element.
To switch to iframe you can use:

browser.switch_to.frame(browser.find_element_by_tag_name('iframe'))

and then use:

pc = browser.find_element_by_name("PURCHASE_ORDER_CODE_NAME")
pc.click()
pc.send_keys("7555425-1")

if you want to switch back to the default content, you can use:

browser.switch_to.default_content()
Sign up to request clarification or add additional context in comments.

10 Comments

I´ve tried :Unable to locate element: [name="PURCHASE_ORDER_CODE_NAME"]
@wmoura12 can you check that is there any iframe available in the html ?
yes. <iframe id="x-auto-510" name="gxt.formpanel-5" style="position:absolute;width:0;height:0;border:0"></iframe>
@wmoura12 i have updated my answer, please check the updated answer.
Your first code block has pc = ....click(). .click() returns void so nothing is going to get assigned into pc and it will likely throw an error. You've got it right in the third block, just update the first block to remove the pc = to avoid the problem.
|
1

The desired element is a dynamic element so to invoke click() on the element you have to induce WebDriverWait for the element to be clickable and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.x-form-field.x-form-text[id$='-input'][name='PURCHASE_ORDER_CODE_NAME']"))).click();
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class=' x-form-field x-form-text ' and contains(@id,'-input')][@name='PURCHASE_ORDER_CODE_NAME']"))).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

Tks for your response. This code returned Timeout. TimeoutException: Message:
TimeoutException is the outcome of failed expected-conditions. Debug your code through find_element_by_* in-conjunction with time.sleep(). If you are able to locate the element, update the question with the observations.
0

Maybe you can try another "selector" approach. Ex(Javascript):

selenium.By.xpath('//*[@data-icon="edit"]')
driver.findElement(by).click()

Comments

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.