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;
}
}
Related
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");
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)
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')]
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")
I have to select a value from drop down button and drop down button contain two value Yes and No
If I select Yes one more question will be trigger on the screen and if I select No, no question will be triggered.
Is the below code correct? Or lets us the easiest way to write this.
if (driver.findElement(By.id(""))== selectByVisibleText("Yes"));
{
String fpal = s.getCell(26, row).getContents();
driver.findElement(By.id("")).sendKeys(fpal);
}
if (driver.findElement(By.id(""))== selectByVisibleText("No"));
{
String fpal = s.getCell(26, row).getContents();
driver.findElement(By.id("")).sendKeys(fpal);
}
This is a basic programming question rather than Selenium, I would suggest you check out a beginners tutorial or two before posting more questions.
Some points though:
You'll need to use an actual element ID in driver.findElement(By.id(""))
There should be no ; at the end of the if statement
You'll probably want to use the selenium method getAttribute to find the selected value of the dropdown box (once you fix point 1)
eg. if (driver.findElement(By.id("element123")).getAttribute("value").equals("Yes"))