selenium webdriver find element by 'href' not working using java - selenium-webdriver

I am creating a page Object model using selenium web driver and trying to link an element which has a 'href'. By creating in this way
[element = driver.findElement(By.partialLinkText("signin")).click();]
I am getting an error like
cannot covert from void to web element.
Can anyone can help me with this

First select element in browser, and copy it's selector(inspect -> copy selector). Then use it as cssSelector. Try not to use link text coz it is language dependent.

hi you are getting above error because
element = driver.findElement(By.partialLinkText("signin")).click();
you are trying to perform action (i.e click) and its object identification (element =...)
together whic h is not correct to make it work plz do it like below
element = driver.findElement(By.partialLinkText("signin"));
element .click();
Also why are you getting the error "cannot covert from void to web element" cause the type of .click() is void for more information please look at official documentationhttp://seleniumhq.github.io/selenium/docs/api/java/index.html
now it will stop giving you error hope this helps you

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

Unable to Locate Input elements withing a Table in serviceNow - Selenium webriver- java

I am trying to input text to a Input field inside a Table in service now. But, the element is not locatable.
Xpath of the element is :
"//*[#id=\"x_f5sl_cl_planning_proposal_table\"]/thead/tr[2]/td[4]/div/div/div/input"
Error :
no such element: Unable to locate element:
I tried using action class as well, But did not work.
Is there any other way to locate this and input values to this field?
Try to verify if Your Xpath is correct with eg. Firefox addon https://addons.mozilla.org/en-US/firefox/addon/try-xpath/?src=api
Your xpath will be without errers if You write it like this:
//*[#id='x_f5sl_cl_planning_proposal_table']/thead/tr[2]/td[4]/div/div/div/input

How can i locate element using ngweb driver?

I am trying to click a button from a angular page.I am using ng web driver as below:
driver.findElement(ByAngular.partialButtonText("LAUNCH")).click();
//Actual launch button
but it shows no such element how can i proceed to get that element
With the minimal information provided on the question: You might want to switch to the angular frame before finding the element.
With the minimal information provided on the question: You might want to switch to the angular frame before finding the element.
Or try waiting for the page to load completely with SyncPage(); or Thread.Sleep(1000);

How can I access the selector field of a By object?

I'm using Java, Selenium Webdriver in Eclipse.
I wrote a helper method to wait for an element present, scroll to it, wait for the element to be visible and click it. Here's what I have:
protected void waitScrollWaitClick(By by, String scroll)
{
wait.until(ExpectedConditions.presenceOfElementLocated(by));
getJse().executeScript("$('.mCustomScrollbar#" + scroll + "').mCustomScrollbar('scrollTo',document.querySelector(\"" + by.selector + "\"), {scrollInertia:0})");
wait.until(ExpectedConditions.visibilityOfElementLocated(by));
getDriver().findElement(by).click();
Now the issue I'm having is in that second line in the method. I am passing a By object. This works for the conventional Webdriver methods on lines 1,3,4. But since we are using a custom scrollbar for our web app, I need to use that JavascriptExecutor class (the getJse()) to scroll on the proper div #id (thus passing in the 'scroll' argument). To use that JSE I just need the CSS selector, not the whole By object. If I add a breakpoint and look, the By object contains a 'selector' field that has what I want (in Eclipse there's a red square icon with an 'F' on it), but I can't seem to access it. I tried with the "by.selector" in the code above, but that is a compile error.
How can use that selector field? I'm not Java expert, so maybe I'm missing something obvious. I guess I don't understand why I can stop on a breakpoint, see the By object I created in the Variables tab, expand the By object and see the 'selector' field I want, but just can't access it.
The easy answer is that you cannot get the CSS selector from a By type, or even WebElement type. This is because the WebElements themselves are found by the By class. In case the By specified was a xpath there would be no way to populate the CSS selector.
The long answer specifically for your issue, to get the CSS Selector would be to create it using Javascript. An example would be Florent B.'s answer here. However, I didn't tried myself and I have no idea if it works for all cases.
Now, to address the general issue, instead of using document.querySelector use document.getElementById in case your element has an id.
Or by using document.evaluate to get your element by xpath. You can find an example in the answer posted here.

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