Selenium cannot find the element under iframe - selenium

I'm trying to find the element under a iframe, and I've switch to the frame, but I still can not find the element
enter image description here
my HTML is in the link: http://pastebin.com/AShYrdxQ

Hi first of all i found only one iframe on the page with id = msgframe and also please note that as per your source code that i frame is commented so not playing any role hence please do not use switch to driver simply use
List<WebElement> commonElements = driver.findElements(By.className("Apps_Title"));
for(int i =0;i<commonElements.size();i++){
System.out.println(commonElements.get(i).getText());
}
and it will work thanks hope this will help you.

Try:
driver.switchTo().frame("needle-frame-id-or-name");
sometimes it's help me too:
driver.switchTo().defaultContent();
driver.switchTo().frame("needle-frame-id-or-name");

Related

Selenium C# - I'm unable to find an element on this page using any of the locators

This was just a random script I made to complete a quiz but I can't seem to access the final element. I want to select the element, click the element and then send some text to the element.
I have tried to access the input box by class name, CssSelector and by XPath.
The website is https://www.16personalities.com/free-personality-test
Here are the XPaths I have tried:
//*[contains(#class, 'email-wrapper')]
//div[contains(#placeholder, 'your#email.com')]
//div[#class="row request-info-wrapper"]
//*[#id='request - email']"
Any help is greatly appreciated as I'm new to the framework and would very much like to know what I'm not understanding about locators! Thank you!
EDIT:
I can't seem to target this element or any of its children:
You have selected wrong tag DIV.Try this following Xpath. All should work.
"//input[#id='request-email']"
Or
"//input[#name='email']"
Or
"//input[#placeholder='your#email.com']"
Your field has a (presently) unique ID of "request-email".
Thus you can simply use, as a CSS selector,
('#request-email')
Then, in you can simply tell Selenium to hit ENTER to save your data. Let me know if you need help doing that.

How to get the clicked element in selenium when we don't know what are we clicking

I am clicking with the help of following lione oc code->
actions.moveToElement(objDriver.findElement(By.id("id_popcode")),coordinates.getX(),coordinates1.getY()-1).doubleClick().build().perform();
Basically i double click at a position(x,y) in our application. Individually we cannot click that particular element bcoz it has to be clicked at particular (x,y) itself. So i want to get the properties of that clicked element(which i click using actions command which i mentioned above) liked id, classname. Can some one help me with this...kinda stuck here..........
edit:
try execute.elementFromPoint() with JavascriptExecutor to get element by coordinates
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement theElement = (WebElement)js.executeScript("return document.elementFromPoint(arguments[0], arguments[1])", coordinates.getX(), coordinates1.getY()-1);
System.out.println(theElement.getAttribute("tagName"));
System.out.println(theElement.getAttribute("class"));
old:
you are using negative value in getY()-1 which mean coordinates above the element, it maybe the parent or preceding-sibling of element try to select it using xpath
WebElement popcodeBefore = objDriver.findElement(By.xpath("//*[#id='id_popcode']/parent::*"));
// Or
// WebElement popcodeBefore = objDriver.findElement(By.xpath("//*[#id='id_popcode']/preceding-sibling::*"));
System.out.println(popcodeBefore.getAttribute("class"));
actions.moveToElement(popcodeBefore).doubleClick().build().perform();
If you have any specific text at that particular coordinates make use of it. I too had the same issue like this where I need to double click on a cell which had text 0.00%. I have done hovering action first using the text and then performed the double-click
Ignore the syntax issues since I am working on the protractor these days
browser.driver.actions().mouseMove(driver.findElement(by.xpath("//*[text()='00')]").build().perform();
and then perform the click
Still, you have issues, check if you have any attribute like ng-click which can be helpful to get the coordinates for that particular location. please always share the HTML code so that It may help us to check more deeply

Not able to click or page not responding to click in phantomjs-selenium in java

I am doing project on different crawlers and trying to mimic user actions. As part of it, I am crawling this url. Here there is a zip code box and I am trying to click on it and extract text from the drop down which will appear after that. I wrote the below code but not sure why it is not working at all. Can anyone please help? I did exhaustive search to find root cause but got nothing. Any suggestions would be much much appreciated.
driver.getUrl(aboveUrl);
WebElement inputBox = driver.findElement(By.id("pincodeInputId"));
inputBox.click();
System.out.println(driver.findElement(By.className("_3mWImx")).getText());
-- This gives null;
Awaiting help !
The reason is the node that you picked is the parent node of the element that has the text
You should use
System.out.println(driver.findElement(By.css("_3mWImx span")).getText());
And that would work. Also note that there are multiple element with the class _3mWImx, so this will only give you the first one. If you are interested in all of them, then you should be using driver.findElements and looping through the result
Actually there are more than one values in the drop down if you want to print all you have to used findElements(). Use this code it will give you desired result :
WebDriver driver=new FirefoxDriver( );
driver.manage().window().maximize();
driver.get("https://www.flipkart.com/moto-e4-plus-fine-gold-32-gb/p/itmevqynuz4fwxca");
WebElement inputBox = driver.findElement(By.id("pincodeInputId"));
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
inputBox.click();
List<WebElement> elements=driver.findElements(By.className("_3mWImx"));
for(WebElement ele:elements)
{
System.out.println(ele.getText()); //It will print innertext of each element
}
Output :
From Saved Addresses
Loginto see your saved addresses

Selinium web driver- Unable to locate href

I trying to locate a link "Taschen" in the below code(<a data-flyout-target="handbags" title="Taschen" href="#">Taschen</a>) using selinium webdriver. Could anyone please guide me
<a data-flyout-target="handbags" title="Taschen" href="#">Taschen</a>
Here are your choices:
By.className
By.cssSelector
By.id
By.linkText
By.name
By.partialLinkText
By.tagName
By.xpath
So assuming that "Taschen" is partial link text
WebElement aLink = driver.findElement(By.partialLinkText("Taschen"));
If you haven't bothered with page loads and proper implicit waits then this might work better
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement aLink = wait.until(
ExpectedConditions.elementToBeClickable(By.partialLinkText("Taschen"))
);
aLink.click();
You are not using java? Update your question to show your code and add a language tag to your question. Your brain isn't a network connected device and we only know what you tell us. :-)
You can also use the XPath as below:-
//a[#title='Taschen']/text()
Code will be as below:-
WebElement tash = driver.findElement(By.xpath("Taschen"));
If you need to get the text then you can use :-
String tash = driver.findElement(By.xpath("Taschen")).getText();
You can also use the contains function in XPath
//a[contains(.,'Taschen')]
Hope it will help you :)

Not able to identify a lenghty linktext in selenium webdriver

I want to identify an element by linktext, I am facing strange issue
If the linktext value is short i.e addFirst, addLast will be able to locate the element by using
driver.findelement(By.linktext("addLast, addFirst")).click
IF the linktext is addmanualreferraltocheckthelenghtF, addmanualreferraltocheckthelenghtF lengthy as above not able to identify the element
Please help me to find the solution
Why don't you try partial link text.
driver.findelement(By.partialLinkText("addLast, addFirst")).click
try out contains method. use the XPATH value and in XPATH use contains for link text.
EG:
.//*[contains(#Linktext, "addmanualreferraltocheckthelenghtF")]
driver.findelement(By.xpath("//*[contains(#Linktext, "addmanualreferraltocheckthelenghtF")]").click
Alternatively you can also use starts with XPATH value.
.//*[starts-with(#linktext,'addmanual')]
driver.findelement(By.xpath("
//*[starts-with(#linktext,'addmanual')]").click
Hope it helps you.