Selector only working after inspecting/selecting element (selenium) - selenium

I work on selenium with java and when I try find element by (ID, xPath, css) all return the same exception:
'Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable
to locate element: {"method":"css selector","selector":"#City"} '
the element inside form where form inside frame,
when I open Dev Tools in Chrome the execution context is set to top. AND my controls are located within form, that is a different context, not accessible from top. when I change context from top to the second option the controls appear
my question: how can I change the execution context from top to second option by selenium with java
so I can locate controls ??
when I use the below code:
driver.switchTo().frame("name of frame");
driver.findElement(By.id("City")).sendKeys("arwa");
the below Exception appear:
Exception in thread "main" org.openqa.selenium.NoSuchWindowException: no such window
HTML CODE
<iframe name="PegaGadgetIfr" id="PegaGadgetIfr" border="0" frameborder="0" src="about:blank" style="height: 1932px; width: 100%; overflow: hidden;" cd_frame_id_="8428a80be89e4d1b565c0da28ec73cc4"></iframe>
html code
<input data-template="" data-test-id="20181209133107059972774" data-ctl="["TextInput"]" type="text" id="City" value="" class="leftJustifyStyle" title="" name="$PpyWorkPage$pAttendanceData$pCity" validationtype="required" placeholder="" maxlength="150" data-changed="false">

Related

Selenium how to upload files to Microsoft Edge

I am using the following code to upload files to a website to a 'file' type element.
The code works fine in Firefox, Chrome and Safari.
However when I run the code against Edge the file is NOT uploaded
driver.setFileDetector(new LocalFileDetector());
selectFile.sendKeys(path);
This error is reported:
The command failed because the specified element is not pointer or keyboard interactable.
If I try using Javascript like this:
document.getElementById('manual_file_selection').sendKeys(path)
I get this: Object doesn't support property or method 'sendKeys'
As stated the same code works fine in Chrome, Firefox and Safari so I don't understand it.
This is the code behind the file upload button:
<div class="jsx-parser">
<div data-xxxxx-element="manual-file-selection">
<div class="button__container">
<label for="manual_file_selection" class="button button--primary" data-dragging="false" data-xxxxx-element="manual-file-selection--label">
<input id="manual_file_selection" type="file" accept="image/jpeg,image/png" data-xxxxx-element="manual-file-selection--input">
<span>Select File</span>
</label>
</div>
</div>
</div>
Anyone had any success uploading files to Edge with Selenium or is it not supported?
Based on your error messages, I'd give some Javascript a try. It's a bit hacky, as we execute JS to reveal the hidden input element, then send keys to it, but I've had success in the past.
// fetch the element
WebElement input = driver.findElement(By.XPath("//input[#type='file']"));
// run JS to reveal the element
JavascriptExecutor executor = (JavaScriptExecutor)driver;
executor.executeScript("arguments[0].style.display = 'block';", input);
// send file path keys
input.sendKeys(path);
It's worth a try. Let me know if this helps at all.

Selenium web driver : org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: [duplicate]

This question already has answers here:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: //*[#id='login-email']
(4 answers)
Closed 3 years ago.
I am clicking on image button, but getting error as:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element
Html:
<img src="../RupeeWeb/images/entry/trade_jm.png" style="width: 25px; margin-bottom: -1px;"/>
My code is:
driver.findElement(By.xpath("//*[#id=\"1556776066373-0-uiGrid-002G-cell\"]/a[1]/img")).click();
Error:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:
I think there must be problem of Wait. Try the code to wait for that particular element.
WabDriverWait wait = new WebDriverWait(driver,20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id=\"1556776066373-0-uiGrid-002G-cell\"]/a[1]/img")));
driver.findElement(By.xpath("//*[#id=\"1556776066373-0-uiGrid-002G-cell\"]/a[1]/img")).click();

Button is not clickable in application and no selenium exception found in console

I'm trying to click on button(which I marked in yellow) using xpath, but it is failing to click and more over no selenium exception found. I tried to click with css selector and ID. Using isdisplayed() - output is true. but with isselected() - output is false.
I Kept Webdriver wait (Visibility, element located, element to be clickable), implicit wait and explicit wait. But nothing is working out.
I'm new to selenium, please help me out
Below are the code
<button id="addNewButton-btnEl" class="x-btn-center" type="button" hidefocus="true" role="button" autocomplete="off" style="height: 19px;">

Selenium return webcontent

I am using selenium to automate web gui tests. I would like to know, if selenium can return html which contains rendered html as a result of some button click?
For example, initial html has <div id="errorSection"></div>. Now, selenium clicks on a button and errorSection div tag is filled up like this:
<div id="errorSection">
<ol>
<li>Password must be 8 characters long</li>
<li>Username has already been taken</li>
</ol>
</div>
Is selenium able to send back rendered html with rendered content?

Unable to use sendkeys for the selected html tag

Unable to use sendKeys for the selected html tag. I am able to select the tag in Chrome console but not while executing selenium.
HTML i am trying to access
<span class="_fp_t">
<form autocomplete="off" action="javascript:void(0);" class="_fp_v">
<input autoid="_fp_7" class="_fp_u textbox ms-font-weight-regular ms-border-color-neutralTertiary ms-font-color-neutralPrimary allowTextSelection hideClearButton placeholderText" role="combobox" autocorrect="off" autocapitalize="off" aria-haspopup="true" style="width: 25px;">
</form>
</span>
I have tried by below code but it is not working
This is the html tag used in Chrome console:
$x("//input[#autoid='_fp_7'][#style='width: 25px;']")
This code used in selenium code:
driver.findElement(By.xpath("//input[#autoid='_fp_7'][#style='width: 25px;']")).sendKeys("testing10#yopmail.com");
Error thrown:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element
(Session info: chrome=37.0.2062.120)
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 31 milliseconds