Selenium script for click the search box in office 365 webmail - selenium-webdriver

when clicking the search field in office 365 webmail the xpath is
.//*#id='primaryContainer']/div[4]/div/div[1]/div[2]/div[1]/div[1]/div/div/div[1]/div[1]/div[1]/div[2]/div[2]/button
but selenium identifies for the first time and not for the second time.
is there any way to write selenium script using
<span class="_n_t ms-font-weight-semilight ms-font-color-neutralPrimary">Search Mail and People</span>
or any way to identify?

You can try finding it by the text it has.
//span[text() = 'Search Mail and People']

Try to use CSS Selector with #FindBy annotation instead of XPATH like:
#FindBy(css="[class='login_textfield textfield required email field normaltext']")
WebElement emailField;
Sorry, I'm not registered, so I cannot provide you deeper example, hope it helps you enough :)
See at:
http://screencast.com/t/rqa9dOoy9iq
Edit:
I saw that you uploaded some source, try:
#FindBy(css="[class='_n_t ms-font-weight-semilight ms-font-color-neutralPrimary']")
WebElement someWebElementVariable;

Related

Appium: Element is not interactable error is getting displayed while tapping on the checkbox

Tried: xpath= //*[#id="mktoCheckbox_52362_0"],
Console Error: Element is not interactable.
Tried: Xpath= //[#id="mktoForm_2768"]/div[10]/div[1]/div[2]/div[2]/label,
console error: Element is not interactable.
Tried: xpath= //*[text()='I agree to the '],
clicking on 'License Agreement' link and open pdf file in other tab.
Applied all the above xpath but still got no result. Please provide some solution to this problem.
Assuming you're trying to automate this page: https://info.couchbase.com/couchbase_server_mobile.html
If you want to open the license agreement in a new tab - the relevant XPath would be
//a[text()='License Agreement']
If you want to tick the checkbox associated with the license agreement you need this one:
//input[#name='termsandConditions']
In both case it's better to use Explicit Wait to ensure that the element is clickable prior to attempting to interact with it via i.e. ExpectedConditions.elementToBeClickable() function
Going forward if you're working on mobile automation you can consider using Appium Studio which provides Copy Unique XPath feature, it can make your life easier when it comes to defining an element locator

how to find the Xpath for below given check box

enter image description here
Please tell me how to get the xpath for check box.
If you are using Chrome browser - one easy way you can use:
Open the Inspect (or just click the F12 key)
Mark the element you need and right click on it (or just right click on the object (the check box) you are looking for)
Choose Copy ---> Copy Xpath
I think the tshirt option is not public yet, did not get it in your site.I tried with shirts, looks like same dev pattern to me, let me know if the solution does not work.
<input id="Classic" class="facetChkBox" type="checkbox" value="brickstyletype:Classic" name=""/>
<label for="Classic"/>
This is the background html code.
As you already know, this is not the classic checkbox html code, so we need to create a xpath for this as shown below
driver.findElement(By.xpath(".//label[#for='Classic']"))
from the point of code reusablity I would suggest a method like this:
public void clickOnCheckbox(String checkbox){
driver.findElement(By.xpath(".//label[#for='"+checkbox+"']")).click();
}
and call it using
clickOnCheckbox("Blousons");
In this way you can use the same code to click on different check boxes, and create a clean code.
to relate more to what I am saying you can go the url
https://www.ajio.com/women-shirts/c/830316016

Find Element using Selenium Webdriver

I am trying to find an element in the website that i am trying to automate but am unable to figure out how to fetch a particular element. I have provided the html below. Please provide some inputs. Thanks.
< div id="Troy_combine" class="sign_in_flow sign_in_flow_overlay troy_overlay epc_modal big_dialog modal_display" > < h3 class="migration"> Welcome back.< /h3>< h3 class="normal">Welcome to Disneyland< / h3>< p class="migration">It looks like you have a account that use the same address and password. Let’s combine them into a single account to make it easier to access both services.< /p>
Note: There are multiple "migration" classes. How will it know which one to pick up??
I am trying to fetch the text shown in Italics. Help required
Selenium Webdriver with Java
I would use a cssSelector like so:
String itext = driver
.findElement( By.cssSelector("div#Troy_combine p.migration")).getText();
Selecting via classes and IDs are always the easiest and most reliable. Do a By.className("migration").
findElement(By.cssSelector("div.migration")).getText();
I think you could select it by ID as well.

Selenium Webdriver FIle Upload error element ice:inputFile

this is my first post and sorry for asking the same question once again. I am stuck with a issue regarding uploading a file in Selenium Web Driver. I have searched a lot in this forum but the solutions are not working for me. The element which is the file Browse button is embedded in the file text area ( i.e. where the path of the file gets printed after the browsing through file browse dialog box), but the upload button is separate.
The entire element code is:
<input class="iceInpFileTxt" type="file" size="35" name="upload">
I am unable to click on the "browse" button using click() method. I have tried using Autoit/Robot also.
The code of the element from JSP page:
<ice:inputFile id="fileUpload" width="600" autoUpload="true"
value="#{practitionerLoadDataBean.inputFile}"
actionListener="#{practitionerLoadControllerBean.browse}"/>
I know the input type is file so sendkeys() should work. The codes I have been trying are:
WebElement elem = driver.findElement(By.xpath("//input[#name='upload']"));
elem.sendKeys("<PATH>");
The error message shows as:
org.openqa.selenium.remote.ErrorHandler$UnknownServerException:Unable to locate element: {"method":"xpath","selector":"//input[#name='upload']"}
Please let me know where I my mistake is. Thanks in advance.
If the element was simply invisible, it would have been found, but you wouldn't be able to interact with it. The usual solution is to look around for frames.
You can't search for elements contained in frames, you have to switch your driver's context to that frame first.
driver.switchTo().frame("frameName");
Then you'll be able to find the element and upload the file the usual way (please, use the sendKeys() method describes by other answers in here).
Please confirm that the input element is visible
Do not click on the browse button, it will open an system level dialogue box to upload the file & Its very tedious to handle this in selenium.
you can use the following method:
driver.find_element(:id,'videoupload').send_keys("E:\\video.flv")
Please check the "\\" in your code.
Please Keep in mind that the upload will work only If the element you send a file should be in the form
Hope this will work for you.
Cheers!!
File Upload Using SendKeys
FirefoxDriver driver = new FirefoxDriver();
driver.get("URl");
File file=null;
try
{
file=new File("file path");
}
catch(Exception e)
{
e.printStackTrace();
}
Assert.assertTrue(file.exists());
WebElement browserButton=driver.findElement(By.id("button Id"));
browserButton.sendkeys(file.getAbsolutePath());
Try this code:
driver.FindElement(By.XPath("/html/body/div[2]/div[5]/div/div/div/div[2]/div[2]/div[1]/div/div[1]")).click();

Selenium WebDriver cannot locate element within an iframe, and throws NoSuchElementException

I realise there are several queries on here for this same problem but none of them provide a solution to my particular problem.
I am running a web driver test that tries to fill out a form for a mail website to find postcodes based on address details. I keep getting this error when trying to locate the first text box:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"css selector","selector":"#ctl00_BodyContent_txtBuildingNumber"}
I have used xpath and the id to try and locate the element but I keep getting the error. I can see that this element is present when the webdriver is running and I have been able to locate another text element on the page and enter text, but I keep getting this error for this field and other fields within the frame.
I am guessing that the problem must be to do with the fact that this field is part of an iFrame.
I have used implicit waits within the test but with no success. I still get the error.
By the sounds of it you'll need to first switch to the iframe element that contains the element that you want to interact with. (Although without seeing the relevant HTML this is a bit of an extrapolated guess).
driver.switchTo().frame();
eg:
driver.switchTo().frame(1);
driver.switchTo().frame(driver.findElement(By.id("id")));
When you've finished interacting with the elements within the frame, you'll need to switch back to the main webpage.
driver.switchTo().defaultContent();
Check your xpath .
try to use simple
driver.switchTo().frame(1);
with wait statement.
sorry a little correction the following worked for me
driver.switchTo().frame(driver.findElement(By.xpath("//*[#id='page-15']/div/p/iframe")));
//*[#id='page-15']/div/p/iframe is the xpath of the frame in which the button i was trying to click was located. (driver is of type WebDriver i.e WebDriver driver ) thank you
The following worked for me
driver.switchTo().frame(myd.findElement(By.xpath("//*[#id='page-15']/div/p/iframe")));
//*[#id='page-15']/div/p/iframe is the xpath of the frame in which the button I was trying to click.(driver is of type WebDriver i.e WebDriver driver)
thank you
you can use wait statement and after using the wait statement use simply
driver.swithcTo().frame();

Resources