java selenium cant find iframe path - java

i'm trying to get into iframe, but i get error like this:
Find element :By.id: fullscreen-app-host
Find element :By.id: fullscreen-app-host
Get Exception: no such element: Unable to locate element: {"method":"css selector","selector":"#fullscreen\-app\-host"}
and here is iframe css:
<iframe class="publishedAppIframe" tabindex="0" aria-hidden="false" id="fullscreen-app-host" scrolling="no" frameborder="0" name="fullscreen-app-host" allow="geolocation; microphone; camera; fullscreen" style="" title="holidays" cd_frame_id_="6a1f85c52ae"></iframe>
i have tryied many different ways, but result always almost the same - can't find element into iframe.
here i paste link to code of methods i use:
https://www.codepile.net/pile/7eygVLY3

your code:
public void selectIframe() {
String parent = driver.getWindowHandle();
for (String childHandle : driver.getWindowHandles()) {
if (!childHandle.equals(parent)) {
driver.switchTo().frame(childHandle);
}
}
}
Problem:
Iframes are not window , its an element you cannot use :
driver.switchTo().frame(childHandle);
if you want to switch to window then use:
driver.switchTo().window(childHandle);
if you want to switch iframe , then find that iframe and then switch to it
eg :
frame = driver.findElement(By.TAGNAME("iframe"));
driver.switchTo().frame(frame);

Related

Selenium / Java : Unable to locate element on a ion search popup

We are trying to automate a flow and it require a click + sign on a below popup window.
We have tried xpath locator but element is not getting located.
and below we get below error:
error : org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <ion-icon color="gray-900" name="ios-add-circle-outline" role="img" class="icon icon-ios icon-ios-gray-900 ion-ios-add-circle-outline" aria-label="add circle-outline"></ion-icon> is not clickable at point (1135, 195). Other element would receive the click: <span class="button-inner">...</span>
Element locator code is
We are using following code in our step definition for it:
Element locator:
#FindBy (xpath = "//*[#name='ios-add-circle-outline']")
private WebElement plusIcon;
To click below code is being used by us.
method ()
> String currentWindow = driver.getWindowHandle();
> driver.switchTo().window(currentWindow);
> Thread.sleep(3000);
> plusIcon.click();
Action class used to overcome above issue.
> Actions builder = new Actions(driver);
> builder.moveToElement(plusIcon);
> builder.click(); builder.perform();

Finding Pseudo Elements in Selenium

I'm trying to find this element (screenshot below) I'm using Java, I tried using cssSelector and xpath none worked.
Technology.click();
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[#id=\"paletteItem:_8827283_1\"]/a/span")));
WebElement VS = driver.findElement(By.xpath("//*[#id=\"paletteItem:_8827283_1\"]/a/span"));
VS.click(); // all of the above works correctly, but after this point it keeps waiting and then erroring.
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#main-content > header > div > h1")));
System.out.println("Found");
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.querySelector(\"#session-0c5d29dffcf04299a02e217d457f7718 > div.item-list__item-details.click()");
HTML:
<div class="item-list__item-wrapper ng-isolate-scope" bb-session-list-item-content="session" tooltip-position="tooltipPosition" expand="sessionListItem.toggleExpand()" is-expanded="sessionListItem.isExpanded()" is-admin-view="isAdminView" can-edit="sessionListItem.canEdit()" can-show-options="sessionListItem.canShowOptions()" can-launch="sessionListItem.canLaunch()" can-launch-phone="sessionListItem.canLaunchPhone()" can-delete="sessionListItem.canDelete()" can-show-reports="sessionListItem.canShowReports()" can-copy-guest-link="sessionListItem.canCopyGuestLink()"><button class="item-list__item session-list-item-content item-list__item--active" id="session-a07f7478cf154c6ea4e9a56e5f1f1bca" aria-label="Show occurrences for session: الإسبوع الثالث_الطرقان" aria-describedby="session-a07f7478cf154c6ea4e9a56e5f1f1bca-details" ng-attr-aria-expanded="{{session.hasOccurrences ? (isExpanded ? 'true' : 'false') : undefined }}" ng-click="sessionListItemContent.sessionClicked()" ng-class="{'item-list__item--active': canLaunch}" aria-expanded="true">
Screen shots:
Website picture
, Code of element

Not Able to click in Radio Button - Selenium

Tried to select from Radio Button, Check on Console the Element is there and its not under Iframe:
$x("//*[#id='featuresCollapse1']/div[1]/label/span")
(2) [span.overlay, span.overlay]
HTML:
<div class="col-6 my-1 feature-input-wrapper text-left">
<input name="radio0" data-index="1" id="Personal Accident for Driver only" hidden="" type="radio"><label data-code="PA-DO" data-value="60" class="radio-inline custom-component featureInput p-0 radio-no form-group">
<span class="overlay" tabindex="0"></span>
<label data-value="60" class="feature-name">Personal Accident for Driver only<span class="option-price font-weight-bold ml-2"> 60 </span> </label></label></div>
the Xpath of the radio is : private final By PAforDriverOnly = By.xpath("//*[#id='featuresCollapse1']/div[1]/label/span");
Tried here to check if it Display or not .. but its not " Reading the Exception message
try {
driver.findElement(PAforDriverOnly).isDisplayed();
System.out.println("driver.findElement(PersonalAccindent).isDisplayed();");
String Persional = driver.findElement(PAforDriverOnly).getText();
System.out.println(Persional);
driver.findElement(PAforDriverOnly).click();
System.out.println("driver.findElement(PersonalAccindent).click();");
//getTextAct(ProceedToCheckoutBtn);
} catch (Exception e){
System.out.println("The Exception Message of Verify Button : "+e);
}
and here tried to use JavaScriptExcutor, but Failed on WebDriverWait,
once to remove it, its reading the JavaExcutor but not Give any Action :
WebElement myElement = driver.findElement(PAforDriverOnly);
new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(PAforDriverOnly));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", myElement );
System.out.println("JavaScriptExcutor - Click on RadioButton");
Thread.sleep(2000);
Btnclick(PAforDriverOnly);
I hope your xpath is wrong,
because your xpath is pointing to label. try to point it to input tag.
use this //input[#id='Personal Accident for Driver only'] or use it on your way to find the element but you need to drill down to input tag.

Unable to Click button in Selenium

Im having difficulties in locating an element which is a finish button within a page. I have used driver.findElementById("finish").click (); and it does not work.
Below are different examples I used but with no success:
for (WebElement Element : driver.findElement(By.id("finish")).findElements(By.tagName("a"))) {
if (Element.getAttribute ("class").contains("criteria-filter")) { Element.click();
break;
}
----------------------------------------------------------------
WebElement click1 = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#id=\"finish\"]")));
((JavascriptExecutor) driver).executeScript("arguments[0].click();",click1);
----------------------------------------------------------------
if(!driver.findElementById("finish").isEnabled())
{
driver.findElementById("finish").click();
}else{
System.out.println("False");
}
Element:
<a id="finish" access="" allof="PA.DEPLOYMENT_CONFIG" class="btn criteria-filter btn-success" href="" ng-click="verifyAllFields(sftpForm) && sftpForm.$valid && create()">Finish
</a>
Class selector is not the best idea as it will fail if there is more elements with the same class.
The best way is to open dev-tools, click ctrl + f, then try to cath your element by xpath like this:
//a[text()='Finish']
When you "cath" this browser will move to that element.

Wrong URL when parsing HTML with Jsoup Android

could you help me with parsing html site?
I need get src of image and link to another page, but I don't know why I get empty list
This is my code:
Elements elems2 = doc.select("div");
for (Element elem2 : elems2) {
if (elem2.attr("class").equals("grid-box-img")) {
System.out.println(elem2.attr("img"));
kfunewphoto.add(elem2.attr("src"));
}
}
and example of html:
<div class="grid-box-img"><img width="680" height="470" src="https://i.stack.imgur.com/c7PGK.png" class="attachment-full wp-post-image" alt="shou-talanty-uspej-uvidet-pervym-clever-russia" /></div>
I need get "http://cleverrussia.com/wp-content/uploads/2014/10/shou-talanty-uspej-uvidet-pervym-clever-russia.png" and the second part of code:
Elements elems = doc.select("h2");
for (Element elem : elems) {
if (elem.attr("class").equals("entry-title")) {
str = elem.text();
kfunews.add(elem.text());
kfunewslist1.add(elem.attr("href"));
}
<h2 class="entry-title">Шоу “Таланты”. Успей увидеть первым!</h2>
And I need get: "http://cleverrussia.com/shou-talanty-uspej-uvidet-pervym/"
This is full code of page - view-source:http://cleverrussia.com/
The error is that you're trying to select img and a as attributes. Check the below code to see how to fix your code.
// Prints the image source
System.out.println(elem2.select("img").attr("src"));
kfunewphoto.add(elem2.select("img").attr("src"));
// Prints the target link
System.out.println(elem.select("a").attr("href"));
kfunewslist1.add(elem.select("a").attr("href"));

Categories

Resources