I am using selenium for my testing a retail website . Once I reached the Checkout page , I am selecting the option as Paypal Where a sandbox url is opening.
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-07L974777B231831F#/checkout/login
I am able to enter the username and password , clicked on Login button.
After that I am redirected to "Agree & Continue " Page . Where I could not perform any action.
I could see clearly the button properties as below
I have tried the below code, but could not perform any action.
WebElement AgreeandContinue= driver.findElement(By.tagName("input"));
AgreeandContinue.click();
You might have many input elements in the same page. What about trying to select by class or id?
WebElement AgreeandContinue= driver.findElement(By.ByClassName('btn'));
or
WebElement AgreeandContinue= driver.findElement(By.ByClassName('continueButton'));
then using submit() instead of click() as the element is a 'submit' type`
FYI : https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebElement.html
Looks like the button has an id defined, so that would be the best locator to use: driver.findElement(By.id("confirmButtonTop));
If that doesn't work, then you might have to add some waits for the button to be clickable.
And if that still doesn't work, then it's possible, as it is with many commercial tools, that the button is actually inside a different iframe. Look further up in the html to confirm if this is the case (it'll have a iframe tag). If that's the case, then you'll have to first switch to the iframe before clicking the button: driver.switchTo().frame(...) . How to identify and switch to the frame in selenium webdriver when frame does not have id
If we look at the HTML you have provided the WebElement with value Agree & Continue is within an <input> tag. So we have to construct a unique css or xpath to identify the WebElement as follows:
cssSelector :
WebElement AgreeandContinue= driver.findElement(By.cssSelector("input#confirmButtonTop"));
OR
xpath :
WebElement AgreeandContinue= driver.findElement(By.xpath("//input[#id='confirmButtonTop']"));
Try with ID, but if it is not you can try with other locators , I suggest you have to use xpaths:
driver.findElement(By.xpath("//input[contains(#id,'confirmButtonTop')]")).click();
or
driver.findElement(By.xpath("//*[contains(#id,'confirmButtonTop')]")).click();
also I will suggest that you can use wait until element to be clickable or visible
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[contains(#id,'confirmButtonTop')]")));
driver.findElement(By.xpath("//input[contains(#id,'confirmButtonTop')]")).click();
or
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[contains(#id,'confirmButtonTop')]")));
driver.findElement(By.xpath("//*[contains(#id,'confirmButtonTop')]")).click();
Related
I have tried a different method to input elements like
Here is xpath I used
By NameOfTheProperty=By.xpath("//fieldset/div/input[#name='name']");
By NameOfTheProperty=By.xpath("//div/input[#name='name']");
By NameOfTheProperty=By.xpath("//input[#name='name']");
Tried with Selenium Builder
WebElement element=driver.findElement(by);
Actions builder = new Actions(driver);
Action mouseOverHome = builder
.moveToElement(element)
.click().sendKeys(text).build();
mouseOverHome.perform();
Tried with
WebElement element=driver.findElement(by);
element.sendKeys(text);
None of the methods is working..I can not able to input text inside the field and It shows
Element not interactable
Here is the site
I hope someone help me to find out the solution..
Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.
Steps to check:
Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the xpath and see, if your desired element is getting highlighted with 1/1 matching node.
xpath you should checks is :
//input[#name='name']
if it is unique, then you can use Javascript executor :
WebElement password_input = driver.findElemenet(By.xpath("//input[#name='name']"));
((JavascriptExecutor) driver).executeScript("arguments[0].setAttribute('value', 'password_should_be_written_here')", password_input)
personally I would use id's if the element has one.
"//*[#id='__BVID__104']"
Make sure you are waiting for the element to be ready.
WebDriverWait wait = new WebDriverWait();
wait.until(ExpectedConditions.elementToBeClickable(element));
If it then times out on wait.until(... then I've found that sometimes an element must first be clicked for it to be exposed.
If this is the case. You will have to inspect the element before it is clicked. Find it's xpath, and see if it changes when it is clicked. If so then create a webElement for that element and have Selenium first click it, before clicking the actual field/element.
I'm trying to do a simple selenium java automation for automating "sign in and sign out of amazon.com site". I'm able to sign in using element locator techniques, like XPath and CSS selector. But for signout, I'm thrown with ElementNotInteractable exception.
Below is the code that I tried(posting the code segment of signout alone).
WebElement element1 = driver.findElement(By.xpath("//header/div[#id='navbar']/div[#id='nav-belt']/div[3]/div[1]/a[1]/span[1]"));
element1.click();
driver.findElement(By.xpath("//a[#id='nav-item-signout']")).click();
I have tried the above code segment with different element locator techniques like CSS selector and etc, but no luck.
Kindly suggest if I can find and click the sign-out link in the flyout menu by any other method.
Thanks.
You can try below code in which explicit wait is implemented so it will wait for the element to click
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement element1 =driver.findElement(By.xpath("//header/div[#id='navbar']/div[#id='nav-
belt']/div[3]/div[1]/a[1]/span[1]"));
element1.click();
ele2=driver.findElement(By.xpath("//a[#id='nav-item-signout']"))
wait.until(ExpectedConditions.elementToBeClickable(ele2));
ele2.click();
Instead of the click() method try this :
WebElement element1 = driver.findElement(By.xpath("//header/div[#id='navbar']/div[#id='nav-belt']/div[3]/div[1]/a[1]/span[1]"));
element1.sendKeys(Keys.RETURN);
driver.findElement(By.xpath("//a[#id='nav-item-signout']")).sendKeys(Keys.RETURN);
And instead of RETURN you can also try ENTER
You can try below code in which mover hover is implemented so it will hover the menu then you can click for sign-out.
WebElement ele = driver.findElement(By.id("nav-link-accountList-nav-line-1"));
Actions action = new Actions(driver);
action.moveToElement(ele).perform();
driver.findElement(By.xpath("//*[#id='nav`enter code here`-item-signout']/span")).click();
I have an issue with located correct Xpath/ID input field, I am taking the following website as an example:
https://garden.lovetoknow.com/vegetable-garden/how-ripen-green-tomatoes-off-vine
After you open the link then scroll down a bit, you will see "write a comment" blue button, click it then fill the text and name, it will appear a reCaptcha example, I tried the following way to click the checkbox, but without success. I would really appreciate if someone can let me a hand on it
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath(
"//iframe[starts-with(#name, 'a-') and starts-with(#src, 'https://www.google.com/recaptcha')]")));
new WebDriverWait(driver, 10)
.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.recaptcha-checkbox-checkmark"))).click();
Seems you were close enough. The name of the <iframe> i.e. a-x2cp4vfbaqu8 looks dynamic, so it would be better to avoid the name attribute and you can use either of the following Locator Strategies:
Using css_selector:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("iframe[src^='https://www.google.com/recaptcha/api2/anchor']")));
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("span#recaptcha-anchor"))).click();
Using xpath:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[starts-with(#src, 'https://www.google.com/recaptcha/api2/anchor')]")));
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("//span[#id='recaptcha-anchor']"))).click();
References
You can find a couple of relevant discussions in:
How to click on elements within an iframe to enable the captcha through the audio using Selenium and Python
Find the reCAPTCHA element and click on it — Python + Selenium
Dealing with reCAPTCHA in Python Selenium
I struggled with this for several days, it's actually very simple. The captcha is located in a frame, and in order to click on it, you need to switch to this frame.
I did it like this with Selenium:
driver.switchTo().frame(driver.findElement(By.xpath("//*[#title='reCAPTCHA']")));
driver.findElement(By.xpath("//span[#id='recaptcha-anchor']")).click();
I want to click a button(to send a form)
<button class="form-button primary">Click here</button>
I find the element like this:
driver.findElement(By.xpath("//button[contains(text(),'Click here')]")).click;
On chorme is working and sending the form but in IE11 is not(sending the form).
To be clear, in IE is finding the element(or an element). But probably is not the correct element.
Addition info:
This is the only button with this text
I can probably find other ways to get this element , but if I rework this path I will need to change all the paths similar to this.
Selenium version:3.14
IE webdriver :3.14
There are several different ways of clicking on something using selenium. I would try using either a javascript click or an action click.
Javascript click:
WebElement element = driver.findElement(By.xpath("//button[contains(text(),'Click here')]"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
Action click:
Actions action = new Actions(driver);
WebElement element = driver.findElement(By.xpath("//button[contains(text(),'Click here')]"));
action.moveToElement(element).click().build().perform();
It's also possible that you are in the wrong frame while you are executing the click.
driver.switchTo.frame("Frame_ID");
You would be able to find the frame ID when you inspect the webpage.
If your usecase is to invoke click() you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
xpath using className and text:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[#class='form-button primary' and text()='Click here']"))).click();
xpath using text:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[text()='Click here']"))).click();
xpath using contains():
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(., 'Click here')]"))).click();
I am performing Automation for a redbus application but I am finding the web elements using firebug and it will highlight the firefox browser but it doesn't work in a chrome browser.
Please review the following screenshots:
Redbus website link
step 1 Open redbus application URL =https://www.redbus.in/
step 2 Click Accounts module
step 3 Click sign or signup link
My XPath is :
.//*[#id='g-signin2']//span[text()='Sign in with Google']
Chrome browser screenshot: Can not identify the webElement
Google sign up link is in Iframe , in order to interact with elements which are inside the frame/iframe , you need to change the focus of your web driver to that particular frame.
How you can do that in your case :
driver.switchTo.frame("//iframe[#class='modalIframe']")
Then you can interact with Sign in with Google.
WebElement signupButton = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(#id,'signed') and text()='Sign in with Google']")))
signupButton.click();
HTH !
To identify and invoke click() on the element with text as Sign in with Google, as the element is within an . So you have to induce WebDriverWait for both the cases, once for the frame to be available and again for the desired element to be clickable and you can use the following solution :
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[#class='modalIframe' and #src='/account?pageName=Home&noReload=noReload']")));
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[#class='abcRioButtonContents']//span[normalize-space()='Sign in with Google']"))).click();
What You have here is modal frame, You should first switch on it, and the do actions on elements:
driver.switchTo().frame("modalIframe");
or maybe this:
driver.switchTo().activeElement()
It looks the login popup is available inside the iframe tag. First navigate to that particular frame as below and then add the sign in xpath step.
driver.switchTo().frame(0);