1

I had used sapui5 with xml view and java project, using Selenium 1.82 for automated testing. When I used By.xpath , NoSuchElementException occurred. I have tried By.xpath(“//*[text()[contains(., ‘”+ 父母 +”’)]]” and By.xpath(“//*contains(@text, ‘”+父母+”’))”) , the same exception happened. How should I do? Would anybody give advised will be deeply appreciated.

Relation.view.xml

<Select id=”relationSelect” selectedKey=”{Page>relation}”>
<item> 
<core:Item key=”1” text=”請選擇”/>
<core:Item key=”2” text=”父母”/> 
<core:Item key=”3” text=”配偶”/>
</item>
</Select>

Test script (driver had been instanced)

WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement  e =  driver.findElement(By.xpath(“//*[text()=’”+ “父母” +”’]”);
wait.until(ExpectedConditions.elememtToBeClickable(e));
e.click();

I also tried By.id(“relationSelect”), got the same exception. The code By.xpath("//[*text()='"+ "父母"+"']"); worked during March 26 between April 17 this year. After the day (April 17th), when I restart run auto testing on May 2 it failed.

ann
  • 21
  • 4

3 Answers3

0

Try this code :

WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement  e = wait.until(ExpectedConditions.elememtToBeClickable(driver.findElement(By.xpath(“//*[contains(text(),’”+ “父母” +”’]”)))));  
e.click();
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0

To click on the element with text attribute set as 父母 you can use the following line of code :

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//Select[@id='relationSelect']/item/core:Item[@key='2']"))).click();
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I also already have tried your method,got the timeoutexception and nosuchelementexception. – ann May 05 '18 at 09:20
  • To resolve `nosuchelementexception` follow the discussion [NoSuchElementExeption, selenium unable to locate element](https://stackoverflow.com/questions/48471321/nosuchelementexeption-selenium-unable-to-locate-element/48472940#48472940) – undetected Selenium May 05 '18 at 09:46
0

I have already fix this problem by using implicitly wait instead of explicit wait.

driver.manage().timeouts.implicitlyWait(30, TimeUnit.SECONDS);
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
ann
  • 21
  • 4