I'm learning robot framework since a couple of weeks, and I have the next situation while making a robot with a real case:
I have a value of the id of a company, and with it, I need to locate the button with that info which is inside of an accordion on the website, the accordion button list is totally variable and can have one or various items
for context, the part of the site is like this:
<div ><div style="background-color: white; margin: 1rem 0px; border-radius: 10px;"><div ><i aria-hidden="true" ></i>Accordion 1</div><div style="padding: 1rem; background-color: rgb(238, 238, 238);"><div ><div><button >Accordion1 op1</button><button >Accordion1 op2</button></div></div></div></div><div style="background-color: white; margin: 1rem 0px; border-radius: 10px;"><div ><i aria-hidden="true" ></i>Accordion2</div><div style="padding: 1rem; background-color: rgb(238, 238, 238);"><div><button style="padding: 0px; box-shadow: 0px 0px 0px 0px; margin: 0px; text-align: inherit;">*id number of a company* *variable text(name of a company)*</button></div></div></div></div>
I tried with a
Click Button //button[.//text()=*id value*]
but in that case, doesn't find anything, and just comes with an error
and the other option, is to use a Get WebElements Keyword, with the container of the buttons, and that lists the webelements but without a direct way to make it match the text value:
[<selenium.webdriver.remote.webelement.WebElement (session="3932a0dd61c3018f5ede7ca31ea475b1", element="59b4ad4d-3410-4e95-b1e5-3d02e07d1894")>]
so I need to find a way make the framework identify the element with the text, or in the WebElements option, to get the text of the html and get the data to make it clickable with the Click Button Keyword
CodePudding user response:
Looks like id value
is not the exactly text content value of any text node inside that button.
So, instead of this //button[.//text()=*id value*]
please try this XPath expression
//button[contains(.,'*id value*')]
So, the entire command line will be
Click Button //button[contains(.,'*id value*')]
CodePudding user response:
it worked flawlessly, saved me a lot of time