HTML code
using Selenium + Java. I need to click the filter button.
Currently, I am using below code but it doen't work.
WebElement filter = driver.findElement(By.linkText("Filter"));
filter.click();
Xpath - //*#id="frmBookingListing"]/div[3]/div1/div[3]/div/div1/div/div[2]/a[2]
cssSelector - .searchFilter
I don't know what's wrong with my code. please help to click on filter button.
Thanks in advance.
Try this:
.//a[#class='btn btn-typ4 searchFilter' and #title='Filter']/span
Related
Below is my code:
//<span class="ui-button-text">Export</span>
I tried all levels to click EXPORT button using below code and it won't work at all. Please advise..
Driver.findElement(By.xpath("//span[#class='ui-button-text']")).click();
Driver.findElement(By.xpath("Driver.findElement(By.xpath("//span[#class='ui-button-text']\")).click();
xpath is not working! any other ways are appreciated..
As per the HTML you have shared to click on the element with text as Export you can use either of the following solutions:
cssSelector:
Driver.findElement(By.cssSelector("span.ui-button-text")).click();
xpath:
Driver.findElement(By.xpath("//span[#class='ui-button-text' and contains(.,'Export')]")).click();
The scenario is:
Try to add experience in linkedin.
Then click on save button to save the added experience.
The below is html code for this button:
<button class="pe-form-footer__action--submit form-submit-action Sans-15px-white-100%" type="submit">
Save
</button>
I am trying to find it by xpath using:
#FindBy (xpath = "//*[contains(text(), 'Save')]")
WebElement saveExperienceButton;
Following screenshot may help:
I will appreciate your help.
if you do not mind css/xpath selectors that do not look very elegant, you can always open up Chrome developer tools on the website you wanna test with Selenium, mark the DOM elements you wanna access and in the context menu choose 'Copy xpath' or 'copy selector':
Try this xpath:
(//*[text()='Save'])[2]
On my profile there are 2 Save buttons - the second one is the skill save. Also, you might want to check this question for the contains syntax.
Creating an XPath using text is a less preferable way. instead of that use other attribute value which is unique.
for ex: in your case
//footer//*[contains(#class, 'form-submit')]
I am trying to click on a link using Selenium WebDriver in Java. My Java:
driver.findElement(By.cssSelector("span[data-seleniumid=\"Address0\"]")).click();
The HTML on my page looks like this:
<span data-seleniumid="Address0" class="ATAddressLine">1 The Road, Town, City, Postcode</span>
The error in Eclipse is:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"css selector","selector":"span[data-seleniumid=\"Address0\"]"}
Thanks
Instead of trying to escape the inner double quotes, just use a single quote instead.
driver.findElement(By.cssSelector("span[data-seleniumid='Address0']")).click();
I would try a different selector like "span.ATAddressLine". Not sure if webdriver likes your attribute "data-seleniumid".
Have a webdriver wait condition like waiting for an element to be clickable and then use your above code.
Thanks for you help all. The element wasn't being found because it was in an iframe popup and Selenium was searching for it in the page behind.
This post: https://stackoverflow.com/a/32836709/6565982 helped.
For anyone in the future my code is now:
WebElement iFrame= driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iFrame);
// Select an address
driver.findElement(By.cssSelector("span[data-seleniumid=\"Address0\"]")).click();
// Switch back to the default page
driver.switchTo().defaultContent();
Thanks again.
I'm trying to achieve a tab of Send sms, Hope this image will help you, what i'm looking for. Please see here.
So, here is source code:
<li id="sendSMS" class="active">
Send SMS
</li>
Now, I tried this source code:
driver.findElement(By.linkText("Send SMS")).click();
Unfortunately, This is NOT working :(
Please help, Surely help would be appreciated!
I don't usually rely on linkText that much Try using xpath with text based search
also, try this
//li[#id='sendSMS']/a
By byXpath = By.xpath("//a[.='Send SMS']");
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(byXpath);
myDynamicElement.click();
EDIT:
Added explicit wait
I have just started working on Selenium Webdriver and wanted to try out a command that will identify any element based on the text it shows in the UI.
The HTML Structure of the attribute is shown below.
<div class="cuesLoginProductName">Select One</div>
i want to identify the div name on the Text "Select One". Can this be done in Selenium Webdriver. I have done it before in Ruby using the command
#browser.div(:text=>'Select One').present?
Please let me know how i can identify the element.
Thanks and Regards
Sushanth.G
Try using xpath //div[text()='Select One']
Driver.findElements(By.xpath("//div[text()='Select One']"));