I have been struggling with this issue for longer time and finally decided to ask. I am quite new to robot framework, selenium and python and wanted to be sure that I checked everything.
So, my issue is with finding ID of a label. Below is label class which id I want to find
<label class="control-label col-sm-3" for="22_11_ahg_23" id="22_11_ahg_23-label">Full name</label>
And below is code I have written in robot framework to find this element
${full_name_id_-label}= get element attribute //*[contains(text(),'Full name')] id
Element Text Should Be id=${full_name_id_-label} Full name
2 second line is kind of debugger for me. I simply want to check whether id was found and stored in variable.
As a result I got
Element with locator 'id=' not found.
I want to store id of this label as it is dynamically changing (as well as id of input field next to it) and differences between id of input field and id of label is "-label" at the end.
I don't know how to locate input field in other way
<input id="22_11_ahg_23" class="form-control" type="text" maxlength="200" mask="" value="">
Does anyone can help me. Here are actually 2 questions:
What I am doing wrong that I cannot find element with locator -> actually why id is empty?
Is there any other way to locate such input field?
P.S. does somebody know how to get debugger working in robotframework in pycharm?
After many tries I have found an issue.
It was "*" in xpath. It should be changed with "label" to work...
Related
Basically I want to input invoices in Xero software for my job. The process is very simple, I have some values that I need to input in some slots. I have a big problem however. The xpath is dynamic (changes every time you refresh).
Basically it changes from something like this:
//*[#id="PaidToName_12ddc347c7bc4f5aa84c452f55660690_value"]
To something like this:
//*[#id="PaidToName_4fea44e4f8a844b4b630b4bf149490d8_value"]
So the numbers keep on changing.
I have tried a starts-with function however I am pretty sure that there are two XPATHs that starts with PaidToName or end with value, therefore this doesn't seem like a solution as I get this error message:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
The other thing to note is that I see many elements that have the "input type hidden" in the HTML code which I am pretty sure play a role with that. Please let me know if there is anything I can do to help.
This is the code I have tried that doesn't work.
button = driver.find_element_by_xpath("//*[starts-with(#id,'PaidToName')]")
button.send_keys('lol')
This is the HTML code I am trying to retrieve
<input type="text" size="24" autocomplete="off" id="PaidToName_4fea44e4f8a844b4b630b4bf149490d8_value" name="PaidToName_4fea44e4f8a844b4b630b4bf149490d8_value" class="x-form-text x-form-field autocompleter x-form-focus" tabindex="10" style="width: 129px;">
You can use xpath with id and class combination, try this :
button = driver.find_element_by_xpath("//*[contains(#id,'PaidToName') and contains(#class,'x-form-text')]")
button.send_keys('lol')
Try below given locator.
driver.find_element_by_xpath("//input[contains(#id,'PaidToName') AND contains(#class,'x-form-text')]")
This is the html on the site:
<input name="PROJECT_CODE" type="text" size="15">
But in fact, if you inspect element, you can edit-in an input value, and the site updates, filling in the blank, i.e.:
<input name="PROJECT_CODE" type="text" size="15" value="VALUE">
So when finding by xpath, I am having trouble changing (let alone locating) input value. This is what I currently have, guessing that value="".
projcode = raw_input("what's the projcode? \n")
projcode_retrieved = driver.find_element_by_xpath("//input[#value=""]")
projcode_retrieved.send_keys(projcode)
Help would be greatly appreciated!
That is how HTML works. Do not use the #value attribute when locating inputs. Instead you can use something that does not change, like:
driver.find_element_by_name("PROJECT_CODE")
you can also try with using xpath for element,
driver.find_element_by_xpath("*//input[#name='PROJECT_CODE']");
I have looked a few solutions on this issue on stackoverflow. Although I cannot seem to find working solution.
There are ton of elements with the id prefix "ext-gen" so most of the answers I have seen will not work.
Here is the HTML
<input type="submit" value="New Player Arrived" id="ext-gen1084">
I'm trying to find this element and then return its value with
get_attribute('value')
You can use the following to find a randomly generated element ID:
driver.find_element_by_css_selector("input[type='submit']")
I am still fairly new to the selenium webdriver scene and need some help. I am trying to use a csv file and the value in a specific column to click a specific checkbox on a page using python.
Here are the options for the checkboxes:
<input id="GroupsElected_0" name="GroupsElected" type="checkbox" value="ALL">
<input id="GroupsElected_1" name="GroupsElected" type="checkbox" value="newtest">
<input id="GroupsElected_2" name="GroupsElected" type="checkbox" value="test">
I can make it click the checkbox if I give it the actual value:
group=browser.find_element_by_css_selector("input[type='checkbox'][value='ALL']").click()
What I want to do is make it click the box of the correct one based on the value in my .csv file. I have tried a bunch of different things with no success. I always get invalid selector or cant find the element.
Here's the latest i have:
group2=browser.find_element_by_css_selector("input[type='checkbox'][value=cells[6]]").click()
The value I want from the csv is in the 7th column, I know I can use DictReader and have it read the column names which I will do once I get this working.
HELP?!!
Your variable is inside the string so python doesn't recognize it as a variable. Try something like
group2=browser.find_element_by_css_selector("input[type='checkbox'][value=" + cells[6] + "]").click()
I'm trying to click the following link using selenium.
<div id="RECORD_2" class="search-results-item">
<a hasautosubmit="true" oncontextmenu="javascript:return IsAllowedRightClick(this);" class="smallV110" href="#;cacheurlFromRightClick=no"></a>
</div>
Which record to click is not known before the code is executed. Record_2 has multiple children, and the one included is the one I want to click. The link is edited for the sake of privacy. I tried to do something like that where name is the record variable, however it doesn't work.
driver.find_element_by_css_selector("css=div#"RECORD_%s" % (name).smallV110")
I'm a complete newbie to selenium so I couldn't figure out a way to sort this out. I would appreciate any help. Thanks!
Note that this is not Selenium IDE and you don't need the css= at the beginning of a selector.
There are multiple ways to locate the link element, e.g.:
driver.find_element_by_css_selector(".search-results-item a.smallV110")
driver.find_element_by_css_selector("[id^=RECORD] a.smallV110") # id starts with "RECORD"
If you know the id value beforehand:
id_i_know = 2
driver.find_element_by_css_selector("[id=RECORD_%d] a.smallV110" % id_i_know)
You don't have to have that smallV110 class attribute check - I've added it to increase chances of not matching other a elements inside the div (not sure what they are, you have not posted the entire HTML).