1

I am trying to use Selenium/Webdriver and Python to automatically fill a form and was successful with all fields but one. I have a feeling it's because it is inside of a div container and I don't know how to specify something inside the container. I am trying to change the value "Blank".

This is what inspect element shows for the form field (highlighted)

The error line is from here:

assignmentGroup = web.find_element_by_xpath('//*div[@class=“input-group ref-container”]//sys_display.sc_req_item.assignment_group')

I have also tried doing the full xpath (copied from chrome) like this:

assignmentGroup = web.find_element_by_xpath('/html/body/div[2]/form/span[1]/span/div[5]/div[1]/div[2]/div[7]/div[2]/div[2]/input')

and like this, with and without the last *@id part:

assignmentGroup = web.find_element_by_xpath('//div[@class="col-xs-10 col-sm-9 col-md-6 col-lg-5 form-field input_controls"]//div[@class="input-group ref-container"]//*[@id="sys_display.sc_req_item.assignment_group"]')

Which gets me this from CLI- Message: no such element: Unable to locate element:>xpath here<

Last, I tried getting whatever attribute was in this box, just to see if I can locate it.

assignmentGroupAttribute = web.find_element_by_css_selector("div.input-group.ref-container").get_attribute('sys_display.sc_req_item.assignment_group')

My 8 hours of experience in Python/HTML/CSS may not be enough for me to figure this out.. Any thoughts?

1 Answers1

0

I think you are making it more complicated than it needs to be. The input element you have highlighted has an id tag, try grabbing it by that

assignmentGroup = web.find_element_by_id("sys_display.sc_req_item.assignment_group")

Rule of thumb is to always search for ID or Name first, those are usually the most reliable. If those aren't available you can go into Xpath or CSS Selector

JD2775
  • 3,658
  • 7
  • 30
  • 52
  • Completely my fault for not including more html code, but it was still not working. I found out from this thread: https://stackoverflow.com/questions/52764405/selenium-cant-find-elements-even-if-they-exist that I need to switch to frame first. Then it worked. I will use ID or name first. Thank you for your help! – beakerpro99 May 11 '21 at 16:07
  • Ah, yep. I had no way to see that :) Good job in figuring it out, iframes can be tricky – JD2775 May 11 '21 at 16:11