Hey I'm new to web automation , I just startes to write my scenarios and link them to related steps using java framework:
I tried different methods for this button :
driver.findElement(By.xpath/className)
and I always got this exception in my code:
org.openqa.selenium.NoSuchElementException
exemple used: WebElement filter = driver.findElement(By.xpath("//*[#id ='sidebarCollapse']"));
filter.click();
Can anyone help me (see the attached image ) ?
To click() on the element you can use either of the following Locator Strategies:
cssSelector:
driver.findElement(By.cssSelector("span#sidebarCollapse[title='Filtres de recherche']")).click();
xpath:
driver.findElement(By.xpath("//span[#id='sidebarCollapse' and #title='Filtres de recherche']")).click();
Ideally to click() on the element you need 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("span#sidebarCollapse[title='Filtres de recherche']"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[#id='sidebarCollapse' and #title='Filtres de recherche']"))).click();
Related
I have received this error for several times:
Unable to locate element: {"method":"xpath","selector":"//li[#id="tablist1-tab3"]"}
Code that I have used is:
options.addArguments("--headless");
options.addArguments("window-size=1200x900");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
WebElement tab = driver.findElement(By.xpath("//li[#id=\"tablist1-tab3\"]"));
tab.click();
Can someone help me with this error?
You need to use WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("li#tablist1-tab3"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//li[#id=\"tablist1-tab3\"]"))).click();
WebElement tab = driver.findElement(By.xpath('//li[#id="tablist1-tab3"]'));
try this
Make sure the element is not inside an iFrame. If it is, then you need to first find the iFrame element and use Selenium's switchTo(). After that you will be able to locate elements inside the iframe.
I'm trying to find a element in selenium with this XPATH. I get this in firefox web browser.
/html/body/div[5]/div[2]/div[9]/div[1]/div[2]/div/div[2]/div[2]/div/div/div[1]/div[2]/div[1]/a
HTML code
<br><h3 class="LC20lb DKV0Md">Gmail by Google</h3><div class="TbwUpd NJjxre"><cite class="iUh30 bc tjvcx">www.google.com<span class="eipWBe"> › gmail</span></cite></div>
My Selenium Code
driver.findElement(By.xpath("/html/body/div[5]/div[2]/div[9]/div[1]/div[2]/div/div[2]/div[2]/div/div/div[1]/div[2]/div[1]/a")).click();
driver.findElement(By.linkText("Sign in")).click();
But it's not working. Help me.
As the element is an Angular element to click on it, you need to use 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[#href='https://www.google.com/gmail/'] h3"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//h3[text()='Gmail by Google']"))).click();
I am new to selenium and trying to write linktext code for the html code
Programmer
Code trial:
driver.findElement(By.linkText("Programmer")).click();
the code above is not working, is something wrong?
linkText should work if the element with the text Programmer is uniquely identified within the HTML. Still as the element is a JavaScript enabled element so to click() on the element you need to use elementToBeClickable() and you can use the following Locator Strategy:
linkText:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("Programmer"))).click();
Alternative
As an alternative you can also use either of the following Locator Strategies:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.labels[href^='repopulateUser']"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='labels' and starts-with(#href, 'repopulateUser')][text()='Programmer']"))).click();
I have searched for an Account in Salesforce and it gives a few search results. But I'm unable to find the element in Selenium.
I have tried using absolute/relative xpath and CSSSelector, LinkText as well.
Used: driver.findElement(By.linkText("ILT_Order1")).click();
ILT_Order1
I am unable to find the element.
Induce WebDriverWait and elementToBeClickable and following xpath.
If still not found then check if there any iframe available on the page.
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#data-seclke='Account'][text()='ILT_Order1']")));
element.click()
As the element is a JavaScript enabled element so to click() on the element you need to use elementToBeClickable() and you can use either of the following Locator Strategies:
linkText:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("ILT_Order1"))).click();
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a[data-seclke='Account'][onmousedown^='searchResultClick'][href]"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#data-seclke='Account' and text()='ILT_Order1'][starts-with(#onmousedown, 'searchResultClick')]"))).click();
I'm writing some code but I cant find the locator of checkbox please anyone help me to find locator! I've posted an image and sample code I've written below.
WebElement target = driver.findElement(By.id("term_and_conditions"));
target.click();
To click the check box you can use either of the following Locator Strategies:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("label[for='term_and_conditions']"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//label[#for='term_and_conditions']"))).click();