I want to disable the button before clicking on it, here is what I have:
<button type="submit" name="shippingAddress_save" value="Continue to Billing >" disabled="disabled">
you can do this in selenium USING JavascriptExecutor as below:
WebElement yourButton= driver.findElement(By.name("shippingAddress_save"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].removeAttribute('disabled','disabled')",yourButton);
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(yourButton));
yourButton.click();
You have to change the properties in the html side after doing click with selenium, but you can't do it with selenium itself, selenium only does what you tell it to do, but if you want change in your UI or your behavior you must have to write code for it.
you can check the below code :
WebElement element=driver.Find(By.xpath("your locator xpath")); JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("arguments[0].removeAttribute('disabled','disabled')",element);
Related
<div id="button" data-testid="widgetButton" class=" chat-closed mobile-size__large">
I have elements with a special character which the Webdriver can't locate.
I'm trying to click on an item, I've tried everything.
my last try:
wd.get(urlSubpage);
wd.findElement(By.cssSelector("[class='widgetLabel']"));
You can click with help of id with webdriver wait till element would be able to receive click.
WebDriverWait wait = new WebDriverWait(driver, 50);
wait.until(ExpectedConditions.elementToBeClickable(By.id("button-body")));
Click with JS
WebElement element = driver.findElement(By.id("button-body"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
I cant locate a button on dialog pages, I tried to use cssselectors, xpaths, but simple i cant locate buttons/texts on modal dialogs.
I attached a screenshot from the code.
What can you recommend?
Thank you!
By.xpath(".//button[.='/"Submit/"'])
or
By.xpath(".//button[#class='btn btn-default'])
If it found but click doesnt work try that javascript from other comment
I presume you are able to identify the element.However unable to click on that.
Try use following options.
Use WebDriverWait and elementToBeClickable to click on the element.
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement elementBtn = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.modal-footer button.btn.btn-default")));
elementBtn.click();
Use Action class to click on the element.
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement elementBtn = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.modal-footer button.btn.btn-default")));
Actions action=new Actions(driver);
action.moveToElement(elementBtn).click().build().perform();
Java Script Executor to click on the element.
JavascriptExecutor js= (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", driver.findElement(By.cssSelector("div.modal-footer button.btn.btn-default")));
Note: If above all options doesn't work.Check if there any iframe avaialable.If so, you need to switch to iframe first.like below.
driver.switchTo().frame("framename"); //name of the iframe.
driver.switchTo().frame(0); //you can use index as well.
You could try this:
JavascriptExecutor js= (JavascriptExecutor) driver;
WebElement webElement=driver.findElement(By.cssSelector("div.modal-footer button.btn.btn-default"));
js.executeScript(“arguments[0].click()”, webElement);
Hope it helps.
Try the bellow xpath:
driver.findElement(By.xpath("//div[#class='modal-footer']//button[contains(#class,'btn-default')]")).click();
I have the following element:
<input type="hidden" data-dojo-attach-point="vn" value="adrija" aria-
hidden="true">
The above element is an element of dropdown and is hidden. The code that I have written is:
private WebElement adrija = Driver.driver.findElement(By.xpath("//input[#value='adrija' and #data-dojo-attach-point='vn']"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", adrija);
It says it's not able to find the element.
Please help. Thanks. :)
Use css selector
driver.findElement(By.cssSelector("input[type='hidden']"))
Or xpath
driver.findElement(By.xpath("//input[#type='hidden']"))
Note : the field has type hidden. You cannot do visible interaction like sendkeys or click as it is invisible
Selenium cannot work on the hidden elements. First, you need the click on the button which opens the drop-down menu. Then you do whatever you want. :).
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
WebElement element = driver.findElement(By.xpath("XPATH"));
element.click();
WebElement childElement = driver.findElement(By.xpath("HidenElementXpath"));
childElement.click();
If the hidden element is in a frame, you need to switch to the frame!!!
Then try to find the element
I am performing automation on my website using selenium webdriver. I am able to login into website but not able to perform click operation on element.
My code attempts are:
WebElement add = BrowserUtilities.driver.findElement(By.xpath("//button[#class = 'btn btn-primary btn-lg']"));
add.click();
I also tried with javascript executor as below :
JavascriptExecutor js = (JavascriptExecutor) BrowserUtilities.driver;
js.executeScript("argument[0].click()", add);
now I am getting exception in console like:
FAILED CONFIGURATION: #BeforeClass launchBrowserTest
org.openqa.selenium.WebDriverException: unknown error: argument is not defined
Please suggest me if any other solution.
It's because of javascript and ajax call present you can try this code :
Find Element using webdriver wait as :
WebDriverWait wait=new WebDriverWait(driver,50 );
WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//button[#type='Cancel']")));
Then perfrom click operation using Actions class as :
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perfrom();
Try with it.
WebDriverWait wait = new WebDriverWait(driver,9000);
WebElement button=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[#class = 'btn btn-primary btn-lg']")));
button.click();
I am unable to click hidden link("WatchBanking") after using move-to-element.
WebElement lnkW2yB=dr.findElement(By.xpath("//a[#href='/personal/ways_to_bank/ways-to-bank-landing']"));
Actions act=new Actions(dr);
act.moveToElement(lnkW2yB).build().perform();
WebElement Span=dr.findElement(By.xpath("//span[contains(text(),'Bank with your Watch')]"));
WebDriverWait wait=new WebDriverWait(dr,20);
wait.until(ExpectedConditions.visibilityOf(Span));
act.moveToElement(Span).build().perform();
Thread.sleep(5000L);
WebElement lnk=dr.findElement(By.linkText("WatchBanking"));
wait.until(ExpectedConditions.visibilityOf(lnk));
act.moveToElement(lnk).click(lnk).build().perform();
It Moves to the span("Bank with your Watch") and shows link("WatchBanking").
But its not clicking on WatchBanking due to immediate disappearance.
Please give me any solution on this.
Selenium sometimes behaves like that only.I would go with JavascriptExecutor at times like this.I've repaced Selenium click by Javascript click and it worked perfectly for that site you've mentioned in comment.
Replace the lnk.click() by the following
WebElement lnk = dr.findElement(By.xpath("//a[text()='WatchBanking']"));
wait.until(ExpectedConditions.visibilityOf(lnk));
JavascriptExecutor js = (JavascriptExecutor) dr;
js.executeScript("arguments[0].click();", lnk);