HTML:
<span class="Select-multi-value-wrapper" id="react-select-27--value">
<div class="Select-placeholder">Select</div>
<div class="Select-input" style="display: inline-block;">
<style>input#undefined::-ms-clear {display: none;}</style>
<input role="combobox" aria-expanded="false" aria-owns="" aria-haspopup="false" aria-activedescendant="react-select-27--value" value="" style="width: 5px; box-sizing: content-box;">
<div style="position: absolute; top: 0px; left: 0px; visibility: hidden; height: 0px; overflow: scroll; white-space: pre; font-size: 13px; font-family: "Open Sans", sans-serif; font-weight: 400; font-style: normal; letter-spacing: normal; text-transform: none;"></div>
</div>
</span>
Code:
Select role = new Select(driver.findElement(By.xpath("//span[#id='react-
select-17--value']/div")));
role.selectByVisibleText("Manager");
also tried:
By.xpath("//*[#id='react-select-27--value']/div[1]");
By.xpath("//*[#id='react-select-27--value']");
I am getting following error.
Unable to locate element: {"method":"xpath","selector":"//span[#id='react-select-17--value']/div"}
please help.
You should not use Select. bec it's only applicable to select tag only.
In your case you have input tag with combobox role . Please try below code
WebElement ele = driver.findElement(By.xpath("//input[#role='combobox' and #aria-activedescendant='react-select-27--value']");
ele.click();
driver.findElement(By.xpath("//*[text()='Manager')");
The dropdown you are targeting is not your conventional HTML <select> element, hence Select class won't work. Instead you should do something like this -
driver.findElement(By.xpath("//span[#class='Select-multi-value-wrapper']")).click();
No you need to locate the exact option. Normally, you cannot see all your React elements inside your inspector. If you are using Chrome browser, you can install this extension and then view your elements, locate them and click on it using Selenium through your regular locators.
As per your code, you can not use Select here because it is a bootstrap drop down so that you can use like below sample code
WebElement DropDownClick = driver.findElement("Locator Value");
DropDownClick.click();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//List of Drop Down locator
List<WebElement> Drop_options = driver.findElements(By.xpath("//span[#class='Select-multi-value-wrapper']//div"));
for (WebElement temp: Drop_options ) {
if (temp.getText().contains("Manager") {
temp.click();
break;
} else {
System.out.println("Continue");
}
Related
I am using the SmartAdmin v1.9.1 template with Angular 5. It came with FontAwesome v4.7.3 Pro, and it uses Bootstrap v3.3.6. I have upgraded FA to v5.10.0, using npm install --save-dev #fortawesome/fontawesome-free.
My question is not a duplicate of this SO question, but similar.
The upgrade has gone smoothly, just needed to change a few fa- icons.
I'm hung up on getting the Bootstrap checkbox icon to display. It displayed fine with v4.7.3, but now I get a small box, where the check mark icon should be - see below.
The CSS below shows the checkbox style. I have tried other content than '\f00c', but same problem. Adjusting the font: does result in changes in size, but the small box remains.
Relevant HTML:
<section>
<label class="checkbox">
<input type="checkbox" name="remember" checked (click)="doCheckbox()">
<i></i>Stay signed in</label>
</section>
Relevant CSS:
.smart-form .checkbox input + i:after {
content: '\f00c';
top: -1px;
left: 1px;
width: 15px;
height: 15px;
font: normal 16px/19px FontAwesome;
text-align: center;
}
.smart-form .checkbox input:checked:hover + i:after {
content: '\f00d';
}
.smart-form .checkbox input:checked:disabled:hover + i:after {
content: '\f00c';
}
I appreciate your help!
Use it like shown below.
Add "fa" class on i tag and move the CSS from i:after tag to i tag
.smart-form .checkbox input+i {
font-family: "Font Awesome 5 Pro";
-webkit-font-smoothing: antialiased;
display: inline-block;
font-style: normal;
font-variant: normal;
text-rendering: auto;
line-height: 1;
}
.smart-form .checkbox input+i:after {
content: '\f00c';
}
.smart-form .checkbox input:checked:hover+i:after {
content: '\f00d';
}
.smart-form .checkbox input:checked:disabled:hover+i:after {
content: '\f00c';
}
<script src="https://kit.fontawesome.com/ff81d4d106.js"></script>
<section class="smart-form">
<label class="checkbox">
<input type="checkbox" name="remember" checked (click)="doCheckbox()">
<i class="fa"></i>Stay signed in</label>
</section>
I have a strange problem . I have a non select drop down with Id as below . There is a no select tag I can see in the code for this field just an input tag nor I can see the text contained in the drop down in the DOM after a select a value . StaffSoCategory is the text box , SelectStaffSoCategory is the icon for the drop down down arrow and StaffSoCategoryValue I believe is for the values displayed .
<input type="text" id="StaffSoCategory" style="width: 126px; font-weight: lighter; border: 1px solid gray; height: 25px; float: left; font-size: 12px; color: black; font-family: Arial; background-color: white;" readonly="readonly" class="ui-autocomplete-input" autocomplete="off" disabled="disabled">
<span role="status" aria-live="polite" class="ui-helper-hidden-accessible">4 results are available, use up and down arrow keys to navigate.</span>
<div id="SelectStaffSoCategory" tabindex="0" style="border-style: solid; border-width: 1px 1px 1px 0px; border-color: gray; width: 22px; height: 29px; background-position: center; cursor: pointer; background-image: url('Images/dropdown.png'); background-repeat: no-repeat; float: left; margin-left: 0px; "></div>
***<input id="StaffSoCategoryValue" type="hidden" value="">***
<ul class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all" id="ui-id-4" tabindex="0" aria-disabled="false" style="z-index: 1; display: none; top: 584px; left: 829px; width: 148px;"></ul>
Once I select the first drop down value (the visible text in drop down is "Confirmed") then value comes in tag but not the visible text of the value that I see , something like below
<input id="StaffSoCategoryValue" type="hidden" value="BCK-Yes">
Is there a way to click on the first value in the drop down I tried with this value "BCK-Yes" and it said element is not visible. I tried selecting the input by Id and then trying Keys down and keys enter that also didn't work.
The code I am trying is
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement revenuePotential = driver.findElement(By.id("SelectStaffSoCategory")); revenuePotential.click();
WebElement revenuePotentialValue = driver.findElement(By.id("StaffSoCategoryValue"));
js.executeScript("arguments[0].click();", revenuePotentialValue);
Console errors I am getting are
StaffSoJsFun.js?v=2019020100000:1 Uncaught TypeError: $(...).autocomplete is not a function
at HTMLDivElement.<anonymous> (StaffSoJsFun.js?v=2019020100000:1)
at HTMLDivElement.dispatch (jquery-2.0.0.js?v=2019020100000:25)
at HTMLDivElement.y.handle (jquery-2.0.0.js?v=2019020100000:25)
(anonymous) # StaffSoJsFun.js?v=2019020100000:1
dispatch # jquery-2.0.0.js?v=2019020100000:25
y.handle # jquery-2.0.0.js?v=2019020100000:25
Access to XMLHttpRequest at '' from origin 'xx.com' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
Well, the input is hidden, so I'm not surprised selenium tells you the element is not visible. Methods that emulate user actions like click() and sendKeys will not be able to affect hidden elements. However, I think the following might work:
First store that element in an object, let's say element and then try the following code to click on that hidden element:
WebDriver driver= new ChromeDriver();
JavascriptExecutor js = (JavascriptExecutor)driver;
driver.get(desiredURL);
//do all the stuff you want to do before `executeScript()`
js.executeScript("arguments[0].click();", element);
Give that a shot?
I am not able to click and select the value from dropdown by using XPath
driver.findElement(By.xpath(".//*[#id='ProcessTypeIGCombo']/span")).click();
MY HTML code is as below:
<input class="ui-igcombo-field ui-corner-all" readonly="" style="float: left; display: block; position: absolute; height: 20px; width: 99.7921%;">
for more details please use the screenshots
I have tried below code to click on the fields but getting errors as
"org.openqa.selenium.WeddriverException:unknown error: Element is not clickable at point(138,353). Other element would receive the the click… display: block;>…."
Code:
WebElement el1 = driver.findElement(By.xapth(".//*#id='BC_PATIENT_COMMUNITY_ENROLLMENT_PATIENT_ID']"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click()", el1);
UI:
Refer Attached Screenshot
HTML code:
<div id="datatab" class="dijitContentPane panel-content dijitStackContainer-child dijitStackContainer-dijitContentPane" style="padding: 0px; overflow: hidden; left: 0px; top: 0px; height: 154px; width: 258px;" selected="true" data-dojo-type="dijit.layout.ContentPane" widgetid="datatab" title="">
<div id="datatabpanel" class="tabpanel" style="height: 100%; overflow:hidden; padding: 0px">
<div class="section-header-outer">
<div id="fieldlistContainer" style="height: 0px;">
<div id="fieldlist" class="dojoDndSource dojoDndContainer" data-dojo-attach-point="containerNode" widgetid="fieldlist">
<div id="category11545">
<div id="field-BC_PATIENT_COMMUNITY_ENROLLMENT_PATIENT_ID" class="category11545 field treenode-leaf-label pentaho-listitem dojoDndItem" fieldid="BC_PATIENT_COMMUNITY_ENROLLMENT_PATIENT_ID" title="BC_PATIENT_COMMUNITY_ENROLLMENT_PATIENT_ID">Patient ID</div>
You are not allowed to click on the div element, rather you can use a workaround to trigger click event by performing "dragAndDrop operation on the same element".
Try below code:
new WebDriverWait(driver, 10).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//div[#style='position: absolute; left: 0px; top: 88px; width: 1366px; height: 677px; display: block;']")));
WebElement el1 = driver.findElement(By.xpath(".//*[#id='field-BC_PATIENT_COMMUNITY_ENROLLMENT_PATIENT_ID']"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click()", el1);
The html you have attached is do not have id attribute with value = BC_PATIENT_COMMUNITY_ENROLLMENT_PATIENT_ID. can you just change your xpath from -
WebElement el1 = driver.findElement(By.xapth(".//*#id='BC_PATIENT_COMMUNITY_ENROLLMENT_PATIENT_ID']"));
To
WebElement el1 = driver.findElement(By.xapth(".//*[#fieldid='BC_PATIENT_COMMUNITY_ENROLLMENT_PATIENT_ID']"));
//or
WebElement el1 = driver.findElement(By.xapth(".//*[#id='field-BC_PATIENT_COMMUNITY_ENROLLMENT_PATIENT_ID']"));
This button is before CSS Sprites
<input type="image" src="/images/search-button.png" value="" id="search-button">
I'm trying to implement CSS Sprites with one of my search form and the problem is that if I use
<input id="search-button" class="sprites1" type="submit" value="">
it will look something like this.
As you can see the image on the right doesn't look right, but it is click-able.
Then I tried with
<span id="search-button" class="sprites1"></span>
Then it looks right! But!! I can't click on it.
So here is my CSS sprites code.
What I have to implement to get it look the one I want and I can click on it?
.sprites1 {
background: url('result.png');
}
#search-button {background-position: -0px -462px;
width:16px; height:16px; float:right; }
The problem here is the default css that the browser uses on elements. You should try resetting that css. I often use the following snippet:
/* reset css of buttons */
.cssresetbutton {
border-width: 0px;
border-style: none;
background: inherit;
font: inherit;
color: blue;
padding: 0px; }
.cssresetbutton:active {
border-width: 0px;
border-style: none;
background: inherit;
outline: 0;
box-shadow: none; }
try adding the cssresetbutton class to your input element and see if it works.
EDIT:
You can also try not using a input[type=submit] element. For example:
<span id="search-button" class="sprites1" onClick="document.getElementById('formid').submit()"></span>
It will submit the form#formid element when clicked.