当前位置:网站首页>[software test competition web application provincial competition] pit jumping record

[software test competition web application provincial competition] pit jumping record

2020-11-10 12:53:26 osc_wbutton

【 Software testing contest Web Application saves competition 】 Pit jumping records

This article is written in The preliminaries passed On the basis of , By default, the latecomers have been exposed to web Application testing , And have some basic knowledge .
This article was written in 2020.11.8 The provincial race is over , I hope no one will jump into these pits in the future .

【 Front row tips 】 Never learned the front end Because of laziness , So the terminology about web pages may be misused , Please discuss it rationally _(:з)∠)_ You can point out the mistakes in the comments section ~

1.frame Handoff

This year's provincial competition function test topic is login Netease cloud to operate ( The first two steps are shown in the figure below )

 Title screenshot
The first step is to click “ singer ”, No problem , Direct copy xpath then click Just go .

The problem is in the second step , Go to the singer page , Find that no matter how you copy “ Chinese female singers ” Of xpath, Even elsewhere on the page xpath, Can't click , You will be prompted “not such element”. Why is that ? Let's take a look at the web structure :

 The red box on the left is the element that the title requires to be located , The lower right red box is the element a label
 I'm afraid I can't see clearly , Cut an enlarged page code

The red box on the top right shows , The required elements of the title are contained in a name called “contentFrame” Of iframe Inside , That's why we can't click . Simply speaking , The automation of web pages is limited by space . Let's take the first step “ singer ” This operation of the page ,“ singer ” The space of the element is Default frame; And the second step is to click “ Chinese female singers ”, It's in another space iframe, We need to get into this through statements iframe To be able to operate automatically :

driver.switchTo().frame("contentFrame");// Get into iframe
driver.switchTo().defaultContent();// Return to default frame

Analogy , The operation above is just like we use Command prompt When , If the current working directory is D disc , And now you want to delete C Packing list A document of ( Here if it's called 233.txt Okay ), So directly del 233.txt It doesn't work , First convert the working directory to C Packing list , Again del 233.txt .

it is to be noted that , In the operation requirements after the title , There are elements in iframe Inside , Some are acquiescing frame Inside , Use the above statement to switch jobs as appropriate frame.

2. Changing xpath

Let's look at the third step of the title :
 The third step
This so-called “ Add to the play list ” Of xpath It's copied like this :

driver.findElement(By.xpath("//*[@id=\"2287551604833444877\"]/td[3]/div/a")).click();

You'll find that you can't click , Show “not such element”. More desperate is , Every time you copy xpath Is not the same . This is because of the button of "net suppressing cloud" , When using Copy relative xpath When , It's copied with a timestamp xpath( It's in the code “id=\” The last string of numbers ), We can't use this at this time xpath 了 ( After all, every moment is different ), We need to adopt absolute xpath, Or say full xpath.
 In general, it is copy xpath, Here copy full xpath
We copied it absolute xpath Long like this :

driver.findElement(By.xpath("/html/body/div[3]/div[1]/div/div/div[3]/div[2]/div/div/div/div[1]/table/tbody/tr[3]/td[3]/div/a")).click();

In normal times, it's OK to use relative , Because it's absolutely too long ()

3.( It's not sure if this is a scoring point ) Use text to locate elements

There is a step like this :

At this point, you can directly

driver.findElement(By.linkText(" model ")).click();

Because of the rush of time , There is no test to see if the operation scores correctly , For reference only .

I didn't expect to use it this year iframe, About two hours wasted ( And there wasn't a lot of it before web Application test article ), I hope this article can provide some help for later comers .

Reprint at will
Probably no one will reprint it (

版权声明
本文为[osc_wbutton]所创,转载请带上原文链接,感谢