Reputation: 131
I have the HTML content as below:
<input type="radio" name="radioButton" value="on" id="radio1" tabindex="0">
<input type="radio" name="radioButton" value="on" id="radio2" tabindex="0">
<input type="radio" name="radioButton" value="on" id="radio3" tabindex="0">
Reference: How to use OR condition for Keywords in Robot Framework?
I am currently trying the logic mentioned in above link.But it's not most relevant to my scenario.
I would like to fetch and select the radio button using it's type, name and id or class.
I want to achieve something like below:
Select Radio Button if //input[@type="radio"] AND //input[name="radioButton"] AND //input[@id="radio2"]
Upvotes: 1
Views: 1433
Reputation: 1
You can do the next
WebDriver driver = new FirefoxDriver(); //it can be any driver, not specifically firefox
WebElement radioButton = driver.findElement(By.xpath("//input[@type='radio' and @name='radioButton' and @id='radio2']");
radioButton.click();
The above function will look for the element and click it. And as @Bryan says, if the id is unique you can look for the element only by its id.
WebDriver driver = new FirefoxDriver(); //it can be any driver, not specifically firefox
WebElement radioButton = driver.findElement(By.id("@id='radio2']");
radioButton.click();
Upvotes: 0
Reputation: 386010
You don't need an if
statement. Simply put all of your conditions in a single xpath. For example:
select radio button //input[@type='radio' and @name='radioButton' and @id='radio2']
Though, if the id is unique then you don't need all that. If id is unique you can use something like:
select radio button //input[@id='radio2']
Upvotes: 2