You should use contains:
equals validates the attribute value is exactly equal to given value. As the attribute class value is "ng-untouched ng-pristine ng-invalid igx-input-group__input" you cannot say @class="ng-invalid"
You should use contains instead
driver.findElement(By.xpath("//div/input[(@formcontrolname='nic_no') and ...
Your xpath would be //h2/text(). See the test here.
P.S. - I have no idea why you need that xpath (since you're not mentioning that in your question) but as a side note: you will not be able to use this xpath with Selenium since Selenium cannot wrap a text node into a WebElement
If you need that for Selenium, use the following approach:
Remove \' from the beginning and from the end. So that your code would look like:
gPath1 = str("//div[@id=\"groups\"]/div/div/div/div/div/div[")
gPath2 = str(i)
gPath3 = str("]/div/div/button")
gPath = gPath1 + gPath2 + gPath3
As mentioned in previous answer using custom loctors or tools to find xpath is not a recommended approach. Learn the xpath functions and appraoches.
You can always use parent elemeent to refer a child element uniquely or combine different attributes together.
in your case you can use :
//*[contains(text(),"Paper") and @class="a-size-small a-...
Automated xpath generators can help sometimes, but will generally be very unstable and you could do better by creating the xpath yourself. Try to find an unique element (maybe one with an 'id' value) as the parent of the element you are trying to reach and then construct your own xpath. Maybe this cheatsheet can help.
for(int i=1; i<sections.size()+1; i++)
Why are you adding 1 to sections size, remove 1
for(int i=1; i<sections.size(); i++)
and also why starting from i=1 ? index starts from 0 to size-1 , so it should be i=0 ?
You create a string
String cityName = "London";
String data = "div[contains(text(),"+ "'"+cityName +"'"+")]";
You can put in a for loop and then use this data value as locator.
You can use the String replace method.
String city = prop.getProperty("data"); // New Delhi
String locatorTemplate = prop.getProperty("locatorKey"); // div[contains(text(),'<state Name>')]
String locator = locatorTemplate.replace(locatorPattern, city); // div[contains(text(),'New Delhi')]
WebElement element = ...
<div class="input group">
<button class="btn btn-default">
<i class="fa fa-clock"></i>
You would want to use the following selector for the ...
Browser supports only XPATH version 1.0 and matches is an XPATH 2.0 method, and so you can use only xpath 1.0 in selenium. The above linked document shows the supported XPATH methods.
so in your case
//mat-option/span[text()="someting" or text()="something" and so on ]
You can use //mat-option/span[condition1 or condition2 or condition3]
With XPath 2.0 or higher you could also use
But sadly the developers of Selenium are still stuck on XPath 1.0.
Are you sure you want "text()" here rather than "."? With text(), the text must all be in one text node: no ...
There're usually more options, e.g.:
currentDriver.FindElement(By.CssSelector("td > div.linkButton"));
Another problem might be with element visibility, you can search this site ...
Try to use developer APIs to perform this kind of actions against public sites like Facebook.
For multiple reasons, logging into sites like Gmail and Facebook using WebDriver is not recommended. Aside from being against the usage terms for these sites (where you risk having the account shut down), it is slow and unreliable.
The ideal practice is to use the ...
Based on the HTML, I would say that the problem you are having is that the page shows and hides fields based on where you are in the checkout process. Because of this, you should probably be using conditional waits - Wait.Until(ExpectedConditions.ElementExists(By.Xpath(yourxpath))); (Do not use my code - I'm familiar with C# so my examples follow C# syntax, ...
//select[@id='pg:pbEdit:conlist' and @value='NEW_CONTACT']
Refers to same element , that is the select tag
It will look for select tag with id pg:pbEdit:conlist and value NEW_CONTACT
But there is no tag like that , in your Dom select tag element has only ID
You should use:
This ensures ...
I have made it big progress but there is last minor problem left.
with the code above want to append all the tables in the pages but it append only the first page repetitively.
df = pd.read_html(driver.page_source)
next_page_btn = driver.find_elements_by_xpath('//*[@id=&...
Get your developers to add element ids, finding elements in this fashion is error prone and breaks your tests whenever the app changes in ways that are hard to diagnose and repair quickly. This kind of test code is a testing anti-pattern.
Here is the seminal work on the broader topic Heuristics of Software Testability (links to a PDF).
A more specific ...
The id attribute of the <div> tag is dynamic which will change each time the webpage is accessed. In these cases you need to construct dynamic locator strategies as follows:
Note: The second <div> is the first/only child of it's parent, the <form> is the first/only child of it's ...