<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);
Related
I am not able to click on the button having Some visibility issues. I need to hover around this first to get the link then i need to click on the same.
<a tabindex="0"
class="cardPreviewLink expand-icon"
aria-label="card opens in new tab"
target="_blank"
id="card-preview-link-19479"
href="/card/19479?$filters#$pattern=10532372&type===&dimension=chargeback_id">
<button class="MuiButtonBase-root MuiIconButton-root" tabindex="-1" type="button">
<span class="MuiIconButton-label">
<svg class="MuiSvgIcon-root open-icon"
focusable="false"
viewBox="0 0 24 24"
aria-hidden="true"
role="presentation">
<path d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z"/>
</svg>
</span>
</button>
</a>
Code trials:
WebDriverWait wait4 = new WebDriverWait(driver, 60);
wait4.until(ExpectedConditions.visibilityOfElementLocated(By.className("cardPreviewLink expand-icon")));
driver.findElement(By.className("cardPreviewLink expand-icon")).click();
Error:
Timeout Exception because of No such Element Exception
The desired element is a dynamic element so to click() on the element you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.cardPreviewLink.expand-icon > button.MuiButtonBase-root.MuiIconButton-root > span.MuiIconButton-label"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='cardPreviewLink expand-icon']/button[#class='MuiButtonBase-root MuiIconButton-root']/span[#class='MuiIconButton-label']"))).click();
You can try to click with webdriver wait for element to receive click.
By buttonBy = By.cssSelector("a.cardPreviewLink.expand-icon > button"));
WebDriverWait wait = new WebDriverWait(driver, 50);
wait.until(ExpectedConditions.elementToBeClickable(buttonBy);
If above approach will not work you can try with click using JS. Here I am just waiting for visibility of element as If element can receive click then First approach should work.
wait.until(ExpectedConditions.visibilityOfElementLocated(buttonBy);
WebElement button=driver.findElement(buttonBy);
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", button);
By.className() won't work with names having spaces - cardPreviewLink expand-icon. Instead try to use cssSelector or xpath.
Xpath Example:
WebDriverWait wait4 = new WebDriverWait(driver, 60);
WebElement element = wait4.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[contains(#class,'cardPreviewLink'][contains(#class,'expand-icon']")));
element.click();
'visibilityOfElementLocated' should work. If it didn't, as mentioned by Debanjan, try with 'elementToBeClickable'.
Also, wait.until will itself return WebElement object. You can use the same to click on it.
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
Dom structure :
<li class="slds-dropdown-trigger slds-dropdown-trigger--click slds-m-left--
x-small" data-aura-rendered-by="534:20;a">
<!--render facet: 537:20;a-->
<!--
render facet: 541:20;a--><button class="bare slds-button uiButton
forceHeaderButton oneUserProfileCardTrigger" aria-live="off" type="button"
data-aura-rendered-by="184:190;a" data-aura-class="uiButton
forceHeaderButton
oneUserProfileCardTrigger"><!--render facet: 185:190;a--><!--render facet:
187:190;a-->
<div class="tooltipTrigger tooltip-trigger uiTooltip" aria-describedby="tt-
for-174:190;a" tabindex="-1" data-aura-rendered-by="179:190;a" data-aura-
class="uiTooltip">
<span data-aura-rendered-by="171:190;a" class="uiImage"
data-aura-class="uiImage"><img data-aura-rendered-by="169:190;a"
src="https://c.ap5.content.force.com/profilephoto/005/T/1"
class="profileTrigger" alt="">
</span><span class="tooltip-invisible"
role="tooltip" id="tt-for-174:190;a" data-aura-rendered-by="181:190;a">View
profile</span>
</div></button><!--render facet: 543:20;a-->
</li>
i tried these lines of code for Logout :
First click on Logout symbol:
WebDriverWait wait3 = new WebDriverWait(driver, 20);
driver.findElement(By.xpath("//img[#class = 'profileTrigger']")).click();
JavascriptExecutor jse = (JavascriptExecutor)driver;
/*exe1.executeScript("arguments[0].click();", newbt);*/
jse.executeScript("scroll(250, 0)");
second click on Logout button :
driver.findElement(By.xpath("//a[#class =
'profile-link-label logout uiOutputURL']"));
I am getting error as Element is not clickable at point.
#SrieedherSanthakumar
I have few that would like to clarify first, whether or not are you dependent on wait call. Like you are clicking on something and want to wait for something and then process with your second click ?
If so, you might have to modify your first call something like below :
WebDriverWait wait3 = new WebDriverWait(driver, 20);
driver.findElement(By.xpath("//img[#class = 'profileTrigger']")).click();
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
JavascriptExecutor jse = (JavascriptExecutor)driver;
/*exe1.executeScript("arguments[0].click();", newbt);*/
jse.executeScript("scroll(250, 0)");
once you have waited for your page to be load or expected id is visible then proceed with your second call. I am not able to see whether you are waiting for your object in the first call to load since you are clicking on profileTrigger before moving forward with your second call.
1.Use scrollTo element by selector - this will ensure element is visible:
WebElement element = driver.findElement(By.xpath("//button[#class='oneUserProfileCardTrigger']"));
((JavascriptExecutor) driver)
.executeScript("arguments[0].scrollIntoView(true);", element);
2.Always use delay or wait after scroll before click. It takes time for browser.
3.If nothing helps - use javascript click. Bad solution as it not like real user do, but will work always:
WebElement element = driver.findElement(By.xpath("//button[#class='oneUserProfileCardTrigger']"));
((JavascriptExecutor)driver)
.executeScript("arguments[0].click();", element);
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);