Get element by using whats inside that element [duplicate] - selenium

This question already has answers here:
How do I find an element that contains specific text in Selenium WebDriver (Python)?
(12 answers)
Closed 3 years ago.
I want to access an element using selenium web driver using the inside text of a button element.
I want to catch this button element using "next" value.
<button>next</button>
How can I do this?

You can use following xpath options to get the element with text next
Option1:
//button[text()='next']
Option2:
//button[contains(.,'next')]
Option3:
//button[contains(text(),'next')]

Related

Trying to run a UI test where my form gets filled out, but it won't [duplicate]

This question already has answers here:
WebDriverWait is not waiting for the element I specify
(2 answers)
How to identify the element with the href attribute using Selenium and C#
(2 answers)
Closed 2 years ago.
I am using Selenium for the first time, and I am trying to run a UI test where a form will be filled out. So far the test can get me to that form, but once on that page, I am not able to fill out the first name in that form (look at last line). Below is how I have written it so far and I have also attached the html elements from dev tools. Can someone explain what I am doing wrong? I am trying to find the element by Name and I have also used ClassName, but my examples don't work.
var driver2 = new ChromeDriver(#"C:\Users\Myname \Desktop\NUnitTestProject1\NUnitTestProject1\bin\Debug\netcoreapp2.1");
driver2.Navigate().GoToUrl("https://portal.crushdata.com/");
driver2.FindElement(By.Name("Email")).SendKeys("email#email.com");
driver2.FindElement(By.Name("Password")).SendKeys("pswrd" + Keys.Enter);
driver2.FindElement(By.ClassName("icon-circle")).Click();
driver2.FindElement(By.ClassName("btn-orange")).Click();
driver2.FindElement(By.Name("FirstName")).SendKeys("My Name");

How to locate an element that doesn't have element name using xpath? [duplicate]

This question already has answers here:
How can I make generated content selectable?
(2 answers)
Closed 3 years ago.
Hi can anyone let me know if it is possible to locale an element that doesn't have element name using xpath? The element I want to click is a 'x' button beside a label, and it doesn't have a name, I find it is "::after" when I inspect element in browser.
::after
You get element using JavaScript. Example how to get content from pseudo element.
element = wait.until(ec.visibility_of_element_located((By.CSS_SELECTOR, "span.business-in-area")))
element_content = driver.execute_script("return window.getComputedStyle(arguments[0], ':before').getPropertyValue('content');", element)

Switch frame if iframe has same name and id in Selenium [duplicate]

This question already has answers here:
Is it possible to switch to an element in a frame without using driver.switchTo().frame("frameName") in Selenium Webdriver Java?
(2 answers)
Closed 3 years ago.
I have frame where id and name is same and I want to switch the frame. How can I do this?
This what I tried:
driver.switchTo().frame("iframe");
driver.switchTo().frame("clntcap_frame");
driver.switchTo().frame("//iframe[#id='clntcap_frame']");
HTML code
<iframe name="clntcap_frame" id="clntcap_frame" style="" xpath="1"></iframe>
In console:
Exception in thread "main" org.openqa.selenium.NoSuchFrameException: No frame element found by name or id iframe
First, make sure that the iframe is present in the DOM. If it is present then followings should work l.
Try this:
In this method, you try to pass the frame element itself.
//To check the element exists or not but avoiding any exception, find all the elements with the id and put them in a list. Since id is a unique identifier, it should return only one.
List<WebElement> frame = driver.findElements(By.id("clntcap_frame"));
//Then check if the list of elements is empty or not. If not, then the frame is present in the DOM
if(!frame.isEmpty()) {
//Since frame is a list we need to get the element in the index 0
driver.switchTo().frame(frame.get(0));
} else {
System.out.println("Frame with this id doesn't exists");
}

Trouble finding elements by xpath [duplicate]

This question already has answers here:
Filling in login forms in Instagram using selenium and webdriver (chrome) python OSX
(9 answers)
Closed 3 years ago.
Having some trouble selecting the input on a form on the instagram page using find_elements_by_xpath.
The source HTML code looks like this:
HTML Code from Page
And this is the code that I'm using, but getting no results when printing the result in console.
inputs = browser.find_elements_by_xpath('//form/div[2]/div/div/input')
You can get information how to use locators here: official-locator-strategies-for-the-webdriver.
You can also need to learn about Explicit and Implicit Waits.
Input has name attribute with value username, xpath:
inputs = browser.find_elements_by_xpath("//input[#name='username']")
Find elements by name:
inputs = browser.find_elements_by_name("username")

How to handle multi select list box using selenium? [duplicate]

This question already has answers here:
How to select multiple options from multi select list using Selenium-Python?
(4 answers)
Closed 3 years ago.
Help me with selenium commands/code to fetch the data from the list. We can only select the data from the list, since entering text(like auto search) is not allowed.
I have used the following code, but couldn't resolve the issue. Also I have doubt regarding which xpath given Do I need to give the xpath of the input field or the drop down list?
*WebElement mySelectElement = driver.findElement(By.xpath("//*[#id='basicBootstrapForm']/div[7]/div/multi-select"));
Select dropdown= new Select(mySelectElement);
dropdown.selectByValue("Arabic");
dropdown.selectByIndex(2);
dropdown.selectByVisibleText("Catalan");*
You need to first click on the dropdwon box and then find out the elemnet you are looking for and then click.Hope this help you.Let me know if this work
driver.findElement(By.id("msdd")).click();
List<WebElement> languages=driver.findElements(By.xpath("//a[#class='ui-corner-all']"));
for(int i=0;i<languages.size();i++)
{
System.out.println(languages.get(i).getText());
if(languages.get(i).getText().equalsIgnoreCase("Arabic"))
{
languages.get(i).click();
break;
}
}