Selenium c# cannot locate element with text

Peiyuan Zhou

I am new to Selenium in C#. I tried to use

wait.Until(ExpectedConditions.ElementIsVisible(By.Id("someId")));
new SelectElement(driver.FindElement(By.Id("someId"))).SelectByText("someText");

I got error like this in my NUnit output:

OpenQA.Selenium.NoSuchElementException : Cannot locate element with text: someText

But when I replace wait.Unitil statement with Tread.Sleep(3000), my test could pass without error.

Need some help. Please advise.

mdementev

It will work:

wait.Until(d => d.FindElement(By.XPath("//*[@id='someId']//*[text()='someText']")));
new SelectElement(driver.FindElement(By.Id("someId"))).SelectByText("someText");

But will be good to refactor this into single until, something like:

wait.Until(d =>
{
new SelectElement(d.FindElement(By.Id("someId"))).SelectByText("someText");
return d;
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Selenium cannot locate an element

Cannot locate child element Selenium

Python Selenium cannot locate element

Cannot locate and click an element using Selenium and Python

Cannot locate class span element with Selenium + Java

Python + Selenium - Cannot locate element by class name

Cannot locate element using Selenium Python

Selenium "Cannot locate element used to submit form"

Selenium: How to locate the element with text Run Insight

selenium Unable to locate element using methods: cannot find elements by id, css_selector, xpath, link text

Selenium find_element(By.XPATH, '') cannot locate the element

Cannot Click Element with Selenium - element is either "not interactable" or "unable to locate"

Cannot get text of element with Selenium

Selenium cannot locate an element in a small window opened from pressing a button

Selenium find(By.XPATH) cannot locate element using array of xpaths

Cannot locate any parts of the body of an element with selenium for python

selenium cannot locate button

Unable to locate element in Selenium

How to locate this <a> element with Selenium?

Selenium 'Unable to locate element'

Impossible to locate an element in selenium

Unable to locate element Selenium:

Unable to locate the element in selenium

Unable to locate element: Selenium

Unable to locate element Selenium

Selenium unable to locate the element

Cannot Locate to review text in booking.com by Selenium Python

How to locate an element by class name and its text in python selenium

How to locate the element with text as My Name as per the HTML through Selenium