unable to find the button below using selenium java webdriver - selenium

i'm using selenium, but unable to find the button below using findElement(By.xpath ... Could someone provide some help? Thanks very much!
<button type='button' class='pzhc' data-ctl data-click='[["processAction", ["LookUpPreview","true",":event","","Rule-HTML-Section"]]]' ><div class='pzbtn-lft' ><div class='pzbtn-rgt'><div class='pzbtn-mid' data-click='...'><img src='webwb/zblankimage.gif' class='pzbtn-i'/> Lookup</div></div></div></button>

Use the class name:
WebElement element = driver.findElement(By.className("pzhc"));

Related

Invalid xpath expression to find a slider element

Very new to Katalon Studio and selenium. Trying to write an automated test using selenium webdriver to change the value of the slider on the webpage.
I am failing to locate the element. Somehting is wrong with my findelement statement. Also once I locate the slider element successfully I don't know how to change the value of the slider. Can you help? or provide some quidance?
<div class="bdr-slider"
<span id="bdrText">bdr Amount</span>
<input min="0" max="15" step"0.5" value="5" type="range">
</div>
WebElement Slider = driver.findElement(By.xpath("*[div(#class,'bdr- slider')]"))
Try this :
WebElement Slider = driver.findElement(By.xpath("//div[#class='bdr-slider']"))
I'm not familiar with specifics of mobile automation, but I think that you need to locate the input element.
This one
<input min="0" max="15" step"0.5" value="5" type="range">
and then maybe call sendKeys method on that element.
You can try this line of code:
driver.findElement(By.xpath("//div[#class='bdr-slider']/input")).sendKeys("10");
Before proceeding, make sure the element is really present in the DOM, and thus making sure the problem is not with the path, enter $x('//div[#class="bdr-slider"]/input') to console in DevTools and see if you can locate the element.
If you can find the element, since you are using Katalon Studio, you can do this:
TestObject slider = new TestObject().addProperty('css', ConditionType.EQUALS, '.bdr-slider input')
or, if you prefer xpath:
TestObject slider = new TestObject().addProperty('xpath', ConditionType.EQUALS, "//div[#class='bdr-slider']/input")
You will need to import these two:
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject as TestObject

Unable to find a radio button in selenium webdriver

I am unable to select radio button in Selenium Webdriver-Java with given html code
<input id="idcc-de81e53f-7cfd-4136-816f-d09d4055eeee" type="radio" value="de81e53f-7cfd-4136-816f-d09d4055eeee" name="panels:0:panel:stepContainer:stepTypeDisplay:optionPanel:options">
<label for="idcc-de81e53f-7cfd-4136-816f-d09d4055eeee">Canada</label>
<br>
<input id="idcc-17c1d432-5cec-4da9-9a02-39986d508770" type="radio" value="17c1d432-5cec-4da9-9a02-39986d508770" name="panels:0:panel:stepContainer:stepTypeDisplay:optionPanel:options">
<label for="idcc-17c1d432-5cec-4da9-9a02-39986d508770">United States</label>
id="idcc-de81e53f-7cfd-4136-816f-d09d4055eeee" most likely to by dynamic id so what you need to do is something like
option 1:
List<WebElement> radioButtons = driver.findElements(By.xpath("//input[#type='radio']"));
foreach(IWebElement button : radioButtons)
{
if(button.getText.Equels("Canada"))
{
button.cilck();
}
}
option 2:
driver.findElement(By.partialLinkText("Canada")).click();
Hi please do it like below
driver.get("file:///C:/Users/rajnish/Desktop/radio.html");
driver.manage().window().maximize();
// for canada
driver.findElement(By.id("idcc-de81e53f-7cfd-4136-816f-d09d4055eeee")).click();
// for United states
driver.findElement(By.id("idcc-17c1d432-5cec-4da9-9a02-39986d508770")).click();
what issues you were facing in doing this its very simple and straight ,please post your sample code that you have tried so that i can help you were you were doing it wrong thanks

selenium and clicking an "a" with href=javascript

I'm trying to click a link and am having difficulties. The relevant HTML code is:
<div id="adHocAddDocDiv" style="display: block;">
<a href="javascript:hideDiv();" style="color:#000">
Close window
</a>
<table border="0">
<tbody></tbody>
</table>
</div>
For code, I have:
driver.findElement(By.xpath("//*[#id='adHocAddDocDiv']/a")).click();
This does find the correct element, however it doesn't seem to execute the JavaScript to close the window that happens if I manually click the link. Any ideas?
UPDATE: Here is the code that finally worked:
WebElement element = driver.findElement(By.xpath("//[#id='adHocAddDocDiv']/a"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
I frequently come across elements that WebDriver doesn't seem to be able to click. In these cases I use the following pattern:
var js = (IJavaScriptExecutor)driver;
js.ExecuteScript("$j(\"div[id='adHocAddDocDiv']\").click();");
This is the C# version. I'm sure the Java form is quite similar.
Try more explicit:
driver.findElement(By.linkText("Close window")).click();
My guess is that there are more <a>'s immediately following that div, and it's not unique enough. Try this:
driver.findElement(By.cssSelector("div#adHocAddDocDiv > a[href*='hideDiv()']")).click()

How to click Onclick Javascript form using Selenium?

This is my source code :
<div class="emph a-center addCard"
Or
<a class="add-link" href="javascript:;" onclick="gotoPaymentAddressForm()">Add a New Credit Card</a
</div>
I need to click "Add New Credit" card which open form on the same page. Unable to do this using Selenium.
Kindly advice.
Try with following:
driver.findElement(By.linkText("Add a New Credit Card")).click();
You can also use following xpath codes:
driver.findElement(By.xpath("//a[#onclick='gotoPaymentAddressForm()']")).click();
or
driver.findElement(By.xpath("//a[contains(text(),'Add a New Credit Card')]")).click();
CSS selector is faster than XPATH so you can try
driver.findElement(By.cssSelector("a.add-link")).click();

Selenium IDE: Click command with no ID

How do I perform click action on a button with no "id".
<a class="ui-button altbuttonfix" onclick="mojarra.jsfcljs(document.getElementById('productionreporttoolbar-productionReportToolBarForm'),{'productionreporttoolbar-productionReportToolBarForm-j_idt43':'productionreporttoolbar-productionReportToolBarForm-j_idt43','userId':'11448','reportName':'','statementName':'productionReport.productionReport','token':'','productionReportId':'1000274'},'report');return false" style="" href="#">
View
It's a class type. Any help is appreciated. Thank you.
Why not just use the class value? I use that as a locator all the time:
Webdriver driver = new FirefoxDriver();
WebElement e = driver.findElement(By.className("ui-button altbuttonfix"));
e.click();
You can use the class to identify this button in this case it would be
css=a.ui-button.altbuttonfix