selenium webdriver : 点击交易 ID

huangapple go评论96阅读模式
英文:

selenium webdriver : click transaction id

问题

以下是您提供的代码的中文翻译部分:

我有一个交易表格

第一列中列出了一个 id我想点击它以打开记录以便编辑

我该如何做呢
我能够导航到交易表格但是这个元素失败了:`new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[text()='"+searchid+"']")));`

有人能帮我调试/给我建议吗非常感谢

WebDriver driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver",
        "C:\\Users\\rahul\\Downloads\\chromedriver\\84\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.setExperimentalOption("useAutomationExtension", false);
driver.get("http://testingapp.workspez.com/login");
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='field_email']"))).sendKeys("rahul@workspez.com");
driver.findElement(By.xpath("//input[@id='field_password']")).sendKeys("Sujeet@19");
driver.findElement(By.xpath("//span[@class='MuiButton-label' and contains(., 'Log In')]")).click();
driver.manage().window().maximize();

new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='MuiButton-label' and contains(., 'Operations')]"))).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='MuiButton-label' and contains(., 'View')]"))).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//li[text()='Transaction(s)']"))).click();

WebElement searchidbox = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='MuiInputBase-input MuiInput-input']")));

searchidbox.sendKeys(Keys.CONTROL + "a");
searchidbox.sendKeys(Keys.DELETE);
searchidbox.sendKeys(searchid);

driver.findElement(By.xpath("//button[@class='MuiButtonBase-root MuiIconButton-root' and @title='Search']")).click();
WebElement search = driver.findElement(By.xpath(".//*[@class='MuiButtonBase-root MuiIconButton-root']"));
search.click();

WebElement searchreacord = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[text()='"+searchid+"']")));
searchreacord.click();

请注意,这里给出的是您提供的代码的翻译版本。如果有任何疑问或需要进一步帮助,请随时询问。

英文:

I have transaction table,

There is a id listed in the first column, I want to click it to open the record to edit it.

How do i do that?
I am able to navigate to transaction table but this element fails new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[text()='"+searchid+"']")));

Can some help debug/ advise me?Thanks so much

selenium webdriver : 点击交易 ID

		WebDriver driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\rahul\\Downloads\\chromedriver\\84\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.setExperimentalOption("useAutomationExtension", false);
driver.get("http://testingapp.workspez.com/login");
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='field_email']"))).sendKeys("rahul@workspez.com");
driver.findElement(By.xpath("//input[@id='field_password']")).sendKeys("Sujeet@19");
driver.findElement(By.xpath("//span[@class='MuiButton-label' and contains(., 'Log In')]")).click();
driver.manage().window().maximize();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='MuiButton-label' and contains(., 'Operations')]"))).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='MuiButton-label' and contains(., 'View')]"))).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//li[text()=('Transaction(s)')]"))).click();		
WebElement searchidbox = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='MuiInputBase-input MuiInput-input']")));
searchidbox.sendKeys(Keys.CONTROL + "a");
searchidbox.sendKeys(Keys.DELETE);
searchidbox.sendKeys(searchid);
driver.findElement(By.xpath("//button[@class='MuiButtonBase-root MuiIconButton-root' and @title='Search']")).click();
WebElement search = driver.findElement(By.xpath(".//*[@class='MuiButtonBase-root MuiIconButton-root']"));
search.click();
WebElement searchreacord = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[text()='"+searchid+"']")));
searchreacord.click();

答案1

得分: 0

可以通过以下任一方法来实现。我已经尝试过,它有效。

element.click()   # 将光标定位在字符串末尾
element.sendKeys(Keys.BACK_SPACE )

其中,element 是该字段的 id。

英文:

You can definitely do that by either of the following method. I have tried and it works.

element.click()   # Positions the cursor at the end of the string
element.sendKeys(Keys.BACK_SPACE )

element is your id of that field

答案2

得分: 0

请查看以下代码:

driver.get("http://testingapp.workspez.com/login");
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='field_email']"))).sendKeys("rahul@workspez.com");
driver.findElement(By.xpath("//input[@id='field_password']")).sendKeys("Sujeet@19");
driver.findElement(By.xpath("//span[@class='MuiButton-label' and contains(., 'Log In')]")).click();
driver.manage().window().maximize();

new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='MuiButton-label' and contains(., 'Operations')]"))).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='MuiButton-label' and contains(., 'View')]"))).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//li[text()='Transaction(s)']"))).click();

WebElement searchidbox = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='MuiInputBase-input MuiInput-input']")));
String searchid = "CIE-00026";
searchidbox.sendKeys(Keys.CONTROL + "a");
searchidbox.sendKeys(Keys.DELETE);
searchidbox.sendKeys(searchid);

driver.findElement(By.xpath("//button[@class='MuiButtonBase-root MuiIconButton-root' and @title='Search']")).click();
WebElement search = driver.findElement(By.xpath(".//*[@class='MuiButtonBase-root MuiIconButton-root']"));
search.click();

WebElement searchreacord = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[text()='"+searchid+"']")));
searchreacord.click();

如果您有任何问题或需要进一步帮助,请随时提问。

英文:

Try below code,

    driver.get("http://testingapp.workspez.com/login");
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='field_email']"))).sendKeys("rahul@workspez.com");
driver.findElement(By.xpath("//input[@id='field_password']")).sendKeys("Sujeet@19");
driver.findElement(By.xpath("//span[@class='MuiButton-label' and contains(., 'Log In')]")).click();
driver.manage().window().maximize();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='MuiButton-label' and contains(., 'Operations')]"))).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='MuiButton-label' and contains(., 'View')]"))).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//li[text()=('Transaction(s)')]"))).click();
WebElement searchidbox = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='MuiInputBase-input MuiInput-input']")));
String searchid ="CIE-00026";
searchidbox.sendKeys(Keys.CONTROL + "a");
searchidbox.sendKeys(Keys.DELETE);
searchidbox.sendKeys(searchid);
driver.findElement(By.xpath("//button[@class='MuiButtonBase-root MuiIconButton-root' and @title='Search']")).click();
WebElement search = driver.findElement(By.xpath(".//*[@class='MuiButtonBase-root MuiIconButton-root']"));
search.click();
WebElement searchreacord = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[text()='"+searchid+"']")));
searchreacord.click();

selenium webdriver : 点击交易 ID

huangapple
  • 本文由 发表于 2020年7月27日 16:00:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/63111048.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定