How to Print the Elements With Text Value That Contains in a List Selenium C#

how to print the elements with text value that contains in a list selenium c#

IList<IWebElement> attachmentList = driver.FindElements(By.ClassName("comment-box"));

foreach (IWebElement element in attachmentList)

it works fine by putting the thread.sleep code

How to get all elements into list or string with Selenium using C#?

You can get all of the element text like this:

IList<IWebElement> all = driver.FindElements(By.ClassName("comments"));

String[] allText = new String[all.Count];
int i = 0;
foreach (IWebElement element in all)
allText[i++] = element.Text;

Is there a way to find elements that have a text value less than a variable?

In this case, you could make your CSS selector a little lighter and change it to div.Price--amount (note that the correct way to select by class attribute is using .{class-name}).

Next thing you probably want, if I understand your problem right, is to select multiple elements and not just the first one. You can achieve this by calling find_elements instead of find_element.

The last thing is the .text() method returns a str object and you need to compare it by its numerical (float) value. You want to convert it first.

for element in driver.find_elements(By.CSS_SELECTOR, "div.Price--amount"):
if float(element.text) < Snipeprice:
print("We've got a match")
except ValueError:
print(value, "is not a valid price")

After I send text to a text box using selenium how do i save that text as a variable(string) and then print that to console

Dylan - Take a look at as a nuget package if you are looking for Random Data.

string rndFirstName = Faker.Name.First();
string rndMiddleName = Faker.Name.First();
string rndLastName = Faker.Name.Last();

then you can find the input box


Then to see what the field value now has:

var newFirst = driver.FindElement(By.Id("firstname").GetAttribute("value");
Console.WriteLine("Name: "+ newFirst);

Related Topics

Leave a reply