When I click the link icon in ck editor initially it worked, but when I re-run the code, it's not clicking the link icon in the ck editor.
This is the command I used initially:
driver.findElement(By.xpath("//*[#id='cke_29']/span[1]")).click();
Use WebDriverWait to handle dynamic element.
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[starts-with(#id,'cke_')][#class='cke_button cke_button__link cke_button_off']"))).click();
As #akshay-patil commented use the a tag. The reason is that the <a> tag is the link itself... not the span!
You should use:
driver.findElement(By.xpath("//*[#id='cke_29']")).click();
Hope this helps!
The desired element is a JavaScript enabled element so to click() on the element you have to induce WebDriverWait for the element to be clickable and you can use either of the following Locator Strategies:
Using CSS_SELECTOR:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.cke_button.cke_button__link.cke_button_off[id^='cke_'][title^='Link']>span.cke_button_icon.cke_button__link_icon"))).click();
Using XPATH:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='cke_button cke_button__link cke_button_off' and starts-with(#id,'cke_')][starts-with(#title,'Link')]/span[#class='cke_button_icon cke_button__link_icon']"))).click();
Related
I have used the below code to click on login button but it is not working:
Trial 1:
driver.findElement(By.xpath("//a[text()='https://www.luxproflashlights.com/customer/account/login/referer/aHR0cHM6Ly93d3cubHV4cHJvZmxhc2hsaWdodHMuY29tLw%2C%2C/']")).click();
Trial 2:
driver.findElement(By.linkText("Log In")).click();
If the element contains both the href attribute and the text Log In you can use either of the following Locator Strategies:
partialLinkText:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.partialLinkText("Log In"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(#href, 'luxproflashlights') and contains(., 'Log In')]"))).click();
Technology:
Salesforce
Lightning
Selenium webdriver
Html:
Code Trials:
driver.findElement(By.xpath("//a[#title='Acq Prospects']"));
driver.findElement(By.linkText("Acq Prospect"));
Error:
Unable to find an element
You simply need to wait object to be visible. You can use the following code;
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.Until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[#title='Acq Prospects']")));
For more informations; link.
Note: Also ensure that there is no any element that overlay your object which you are trying to find.
To locate the desired element you need to induce WebDriverWait for the elementToBeClickable and you can use either of the following solutions:
cssSelector:
WebElement Acq_Prospects = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.slds-context-bar__label-action.dndItem[href='/lightning/o/Acq_Prospect__c/home']")));
xpath:
WebElement Acq_Prospects = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='slds-context-bar__label-action dndItem' and #href='/lightning/o/Acq_Prospect__c/home']")))
I am using switching to an iframe using the below statements but on the final wait I get web element not found. Does anyone have any suggestions? I have trolled through google for about a day trying different techniques. None have worked so far
WebDriver driver = DriverFactory.getWebDriver()
WebDriverWait wait = new WebDriverWait(driver, 15)
driver.switchTo().defaultContent()
WebElement iframe = driver.findElement(By.cssSelector(".b-iframe__iframe"))
driver.switchTo().frame(iframe)
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
'fieldset.radio-switch-group')))
Screen shot of HTML below image
As per the HTML you have shared to locate the desired WebElement you have to:
Induce WebDriverWait for the desired frame to be available and switch to it.
Induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:
Using cssSelector:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe.b-iframe__iframe[src*='securetest']")));
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("fieldset.radio-switch-group#balance-type")));
Using xpath:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[#class='b-iframe__iframe' and contains(#src,'securetest')]")));
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//fieldset[#class='radio-switch-group' and #id='balance-type']")));
Here you can find a relevant discussion on Ways to deal with #document under iframe
<a class="action showcart active" data-bind="scope: 'minicart_content'" href="http://52.14.171.179/xstpl/checkout/cart/">
I have tried this one but unable to proceed -
driver.findElement(By.linkText("cart")).click();
As per the HTML you have provided to invoke click() the element you have to induce WebDriverWait for the desired element to be clickable and you can use the following solution:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.action.showcart.active[href='http://52.14.171.179/xstpl/checkout/cart/']"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='action showcart active' and #href='http://52.14.171.179/xstpl/checkout/cart/']"))).click();
findElement(By.partialLinkText("cart"))
And make sure that the string "cart" is case sensitive
The search button is inside the frame and I am connecting to the frame with the below code.
driver.switchTo().frame("autoCompleteDialogIF");
I am able to go the frames section.
Search button syntax:
Find
Here in the frame section I have text box and when I enter the values in text box and perform search the data is not retrieving which matches with the text.
Code used:
WebElement elementclick = driver.findElement(By.xpath(".//*[#id='filterPanelFindButton']/a"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", elementclick);
Try to click on element using java-script executor method.
WebElement elementclick = driver.findElement(By.xpath("//a[contains(text(), 'Find')]"));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", elementclick);
OR
Try to click on element using xpath locator with Explicit wait method.
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//a[contains(text(), 'Find')]"))));
driver.findElement(By.xpath("//a[contains(text(), 'Find')]")).click();
I think you can just use like this:
driver.findElement(By.linkText("Find"))