English 中文(简体)
点击按钮|硒
原标题:Clicking on a button | Selenium

Website: https://eljur.ru/login. This is a site where I want to enter data and parse the login page. But there is a problem: I know how to click on the buttons, but here at the beginning there is a field "Выберите образовательное учреждение"("Choose an educational institution") where you need to click and a search will appear, where you also need to find your school. Please help me make it so that I can click on "Выберите образовательное учреждение"("Choose an educational institution") and go to the school search.[enter image description here](https://i.stack.imgur.com/G0yyK.jpg)

我试图找到类为“form-select-button-icon-left”和“form-seelect-button_placeholder”的元素并单击,但没有成功。

问题回答

你可以试试这个代码。既然你似乎是一个新的贡献者,我就把完整的课程发给你。

package basics;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

import static org.openqa.selenium.support.ui.ExpectedConditions.numberOfElementsToBeMoreThan;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;

public class Eljur {
    private static WebDriver driver;
    private static final Duration TIMEOUT_DURATION = Duration.ofSeconds(30);

    public static void main(String[] args) {
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("https://eljur.ru/login");
        customWait(1);
        findElement(By.cssSelector("div[role= combobox ]")).click();

        findElement(By.cssSelector("input.form-input__input")).sendKeys("Y");
        findElements(By.cssSelector("div.form-select-option")).get(0).click();
        driver.quit();
    }

    public static void customWait(int seconds) {
        try {
            Thread.sleep(seconds * 1000L);
        } catch (Exception ignored) {
        }
    }

    public static WebElement findElement(By by) {
            return waitFor(visibilityOfElementLocated(by));
    }

    public static List<WebElement> findElements(By by) {
            return waitFor(numberOfElementsToBeMoreThan(by,0));
    }

    public static<T> T waitFor(Function<WebDriver,T> function) {
            return new WebDriverWait(driver, TIMEOUT_DURATION)
                    .until(function);
    }
}




相关问题
C# Building An Array with Button Entries

I have a set of buttons that I want to add into an array so that they are ordered. The buttons I have are: Monday0700Button Monday0730Button Monday0800Button Monday0830Button and so on. How do I ...

Text in disabled and css styled button shows movement in IE

I have disabled and css styled buttons. In Firefox, disabled buttons do not move at all when pressed (which is what is expected), in IE, the text in the buttons still moves a few pixels. Why does ...

Where is Button.DialogResult in WPF?

In System.Windows.Forms.Button there is a property DialogResult, where is this property in the System.Windows.Controls.Button (WPF)?

How to create a submit button template in Oracle APEX?

I m trying to create a template for a button in Oracle APEX but I don t seem to have access to the appropriate substitution strings to make it work. For non-templated buttons APEX seems to insert a ...

Removing text from HTML buttons on all browsers?

We have buttons of many sizes and colors that use background images. There is a label on the background image itself, but we need to keep the button s text in the HTML for usability/accessibility. How ...

Back button loop with IFRAMES

In my (school) website we use Iframes to display class blogs (on blogger). This works well EXCEPT if the user then clicks on (say) a photo inside the iframe. Blogger (in this case) then displays the ...

ruby on rails on click events

I am so sorry if this question seems too easy but I can t seem to find it anywhere. I am creating a ruby in steel project. I have created a html.erb and rb file in a vs project (ruby on rails). My ...

热门标签