0

I'm having trouble locating an element. I'm trying to locate it and enter some data into the field. I notice that the class name has spaces and ID is generated automatically (compare these to other forms) so can't use the ID for the automation as I want to automate this to create new forms and will be using the 'Description' field every time.

Below is the html for the Description field, which I'm trying to locate.

<input size="15" maxlength="255" class="acitem description s-description ui-autocomplete-input" spinner="/assets/spinner-48c6e73f2bbe9ea753f7f8e5410541a8138d19d657ddd532b2765335ed3d62bf.gif" auto_complete="true" data-autocomplete-url="/items/auto_complete" data-autocomplete-renderer="item_autocomplete_renderer" data-autocomplete-delay="250" type="text" name="invoice[invoice_lines_attributes][68345][description]" id="invoice_invoice_lines_attributes_68345_description" autocomplete="off">

The codes that I'm using so far has failed.

test_1 = driver.find_element_by_css_selector('.acitem.description.s-description.ui-autocomplete-input')
test_1.send_keys("HELLO WORLD")

test_2 = driver.find_element_by_css_selector("input[class='acitem description s-description ui-autocomplete-input']")
test_2.send_keys("HELLO WORLD")

test_3 = Select(driver.find_element_by_xpath("//*[@class='acitem description s-description ui-autocomplete-input']"))
test_3.send_keys("HELLO WORLD")

Did I got the code wrong or is there some workaround with the class name that has spaces? Thanks.

1
  • your code is work using html above, except in select element Commented Nov 7, 2018 at 9:06

3 Answers 3

1

Thanks for all your help. I solved by using start-with and contains. Below is my code.

invc_desc =driver.find_element_by_xpath("//input[starts-with(@class,'acitem') and contains(@class,'s-description')]")
invc_desc.clear()
invc_desc.send_keys("HELLO WORLD")
Sign up to request clarification or add additional context in comments.

Comments

0

Try with xpath

//input[starts-with(@id,'invoice_invoice_lines_attributes_')]

Comments

0

I almost all the cases, all the elements from the DOM can be accessed via XPATH. In your case I would go with the following:

element = driver.find_element_by_xpath("//input[@id='acitem description s-description ui-autocomplete-input']")

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.