People who code: we want your input. Take the Survey

Hot answers tagged

4

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 ...


4

Your xpath would be //h2/text()[2]. 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: ...


2

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[2]/div[") gPath2 = str(i) gPath3 = str("]/div/div/button") gPath = gPath1 + gPath2 + gPath3 driver.find_element_by_xpath(gPath).click()


2

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-...


1

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.


1

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 ?


1

You create a string String cityName = "London"; String data = "div[contains(text(),"+ "'"+cityName +"'"+")]"; System.out.println(data); You can put in a for loop and then use this data value as locator.


1

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 = ...


1

<div class="input group"> <input id="end_time"></input> <span class="input-group-btn"> <button class="btn btn-default"> <i class="fa fa-clock"></i> </button> <span> </div> You would want to use the following selector for the ...


1

https://developer.mozilla.org/en-US/docs/Web/XPath/Functions 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 ] //mat-...


1

You can use //mat-option/span[condition1 or condition2 or condition3] With XPath 2.0 or higher you could also use //mat-option/span[matches(., 'aaa|bbb|ccc')] 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 ...


1

//div[contains(text(), 'Revenue Report')] //td[contains(string(), 'Revenue Report')] use any of the above locator, the text is inside div tag and not td.


1

There're usually more options, e.g.: // CSS currentDriver.FindElement(By.CssSelector("td > div.linkButton")); currentDriver.FindElement(By.CssSelector("div.linkButton")); // xPath currentDriver.FindElement(By.XPath("//div[text()='Revenue Report']")); Another problem might be with element visibility, you can search this site ...


1

Xpath can find the previous sibling of any field in the DOM. Try using xpath like this: "//div[text() = '" + user_login.email + "']/preceding-sibling::div/a"


1

Use the below keyword and locator: Click Element //span[text()='kw']/../*[@class="Select-value-icon"] Click Link match is based on "on link text and href." as span is not a link it may not work


1

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 ...


1

By.XPath("//*[@data-qa='homephone-update' and @class='ng-invalid']"); Try this


1

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, ...


1

//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: //select[@id='pg:pbEdit:conlist']/option[@value='NEW_CONTACT'] ` This ensures ...


1

I have made it big progress but there is last minor problem left. "df.append(pd.read_html(driver.page_source)[0])" 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)[0] while True: next_page_btn = driver.find_elements_by_xpath('//*[@id=&...


1

This will help you //p[@class='customer-service']/text()[normalize-space()][1]


1

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 ...


1

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: xpath //div[starts-with(@id, 'post-body-')]/div/form/input Note: The second <div> is the first/only child of it's parent, the <form> is the first/only child of it's ...


Only top voted, non community-wiki answers of a minimum length are eligible