我想使用Selenium库通过python在网站上测试脚本。 唯一的问题是,我必须先修改脚本,在运行它之前删除脚本的一部分。 下面是脚本和我想删除的部分
要删除的零件
//alert(data);
if(data === 'BAD'){
$('.win_tr').show();
$('.winText').html('<img src="/images/icons/cross.png" /> Je hebt niet genoeg spins om aan het geluksrad te draaien!');
wheelSpinning = false; // Reset to false to power buttons and spin can be clicked again.
脚本
<script>
// Create new wheel object specifying the parameters at creation time.
var theWheel = new Winwheel({
'numSegments' : 12, // Specify number of segments.
'outerRadius' : 212, // Set outer radius so wheel fits inside the background.
'textFontSize' : 18, // Set font size as desired.
'textDirection' : 'reversed',
'segments' : // Define segments including colour and text.
[
{'fillStyle' : '#eae56f', 'prize' : '0', 'text' : '10 Eerpunten'},
{'fillStyle' : '#89f26e', 'prize' : '1', 'text' : '10 Credits'},
{'fillStyle' : '#7de6ef', 'prize' : '2', 'text' : '250 Hoeren'},
{'fillStyle' : '#e7706f', 'prize' : '3', 'text' : '$10.000.000'},
{'fillStyle' : '#eae56f', 'prize' : '4', 'text' : 'Geen Prijs'},
{'fillStyle' : '#89f26e', 'prize' : '5', 'text' : '50 Eerpunten'},
{'fillStyle' : '#7de6ef', 'prize' : '6', 'text' : '50 Credits'},
{'fillStyle' : '#e7706f', 'prize' : '7', 'text' : '$25.000.000'},
{'fillStyle' : '#eae56f', 'prize' : '0', 'text' : '250 Hoeren'},
{'fillStyle' : '#89f26e', 'prize' : '1', 'text' : 'Geen Prijs'},
{'fillStyle' : '#7de6ef', 'prize' : '2', 'text' : '500 Hoeren'},
{'fillStyle' : '#e7706f', 'prize' : '3', 'text' : '1000 Hoeren'}
],
'animation' : // Specify the animation to use.
{
'type' : 'spinToStop',
'duration' : 5, // Duration in seconds.
'spins' : 8, // Number of complete spins.
'callbackFinished' : 'alertPrize()'
}
});
// Vars used by the code in this page to do power controls.
var wheelPower = 0;
var wheelSpinning = false;
// -------------------------------------------------------
// Function to handle the onClick on the power buttons.
// -------------------------------------------------------
function powerSelected(powerLevel)
{
// Ensure that power can't be changed while wheel is spinning.
if (wheelSpinning == false)
{
// Reset all to grey incase this is not the first time the user has selected the power.
document.getElementById('pw1').className = "";
document.getElementById('pw2').className = "";
document.getElementById('pw3').className = "";
// Now light up all cells below-and-including the one selected by changing the class.
if (powerLevel >= 1)
{
document.getElementById('pw1').className = "pw1";
}
if (powerLevel >= 2)
{
document.getElementById('pw2').className = "pw2";
}
if (powerLevel >= 3)
{
document.getElementById('pw3').className = "pw3";
}
// Set wheelPower var used when spin button is clicked.
wheelPower = powerLevel;
// Light up the spin button by changing it's source image and adding a clickable class to it.
document.getElementById('spin_button').src = "spin_on.png";
document.getElementById('spin_button').className = "clickable";
}
}
// -------------------------------------------------------
// Click handler for spin button.
// -------------------------------------------------------
function startSpin()
{
// Ensure that spinning can't be clicked again while already running.
if (wheelSpinning == false)
{
// Based on the power level selected adjust the number of spins for the wheel, the more times is has
// to rotate with the duration of the animation the quicker the wheel spins.
if (wheelPower == 1)
{
theWheel.animation.spins = 3;
}
else if (wheelPower == 2)
{
theWheel.animation.spins = 8;
}
else if (wheelPower == 3)
{
theWheel.animation.spins = 15;
}
// Disable the spin button so can't click again while wheel is spinning.
document.getElementById('spin_button').src = "spin_off.png";
document.getElementById('spin_button').className = "";
$.ajax({
url: '/ajax/wheeloffortune.php?getnumber',
type: 'post',
data: {},
dataTupe: 'json',
success: function(data) {
//alert(data);
if(data === 'BAD'){
$('.win_tr').show();
$('.winText').html('<img src="/images/icons/cross.png" /> Je hebt niet genoeg spins om aan het geluksrad te draaien!');
wheelSpinning = false; // Reset to false to power buttons and spin can be clicked again.
}else{
resetWheel();
var stopAt = (data);
// alert(data);
theWheel.animation.stopAngle = stopAt;
// Begin the spin animation by calling startAnimation on the wheel object.
theWheel.startAnimation();
// Set to true so that power can't be changed and spin button re-enabled during
// the current animation. The user will have to reset before spinning again.
wheelSpinning = true;
$.ajax({
url: '/ajax/wheeloffortune.php',
type: 'post',
data: {start_spin:true},
dataTupe: 'json',
success: function(data) {
},
error: function (data) {
// alert('Something went wrong');
$('.win_tr').show();
$('.winText').html('<img src="/images/icons/cross.png" /> Er is iets fout gegaan!');
wheelSpinning = false; // Reset to false to power buttons and spin can be clicked again.
}
});
}
},
error: function (data) {
// alert('Something went wrong');
$('.win_tr').show();
$('.winText').html('<img src="/images/icons/cross.png" /> Er is iets fout gegaan!');
wheelSpinning = false; // Reset to false to power buttons and spin can be clicked again.
}
});
}
}
// -------------------------------------------------------
// Function for reset button.
// -------------------------------------------------------
function resetWheel()
{
theWheel.stopAnimation(false); // Stop the animation, false as param so does not call callback function.
theWheel.rotationAngle = 0; // Re-set the wheel angle to 0 degrees.
theWheel.draw(); // Call draw to render changes to the wheel.
// document.getElementById('pw1').className = ""; // Remove all colours from the power level indicators.
// document.getElementById('pw2').className = "";
// document.getElementById('pw3').className = "";
}
// -------------------------------------------------------
// Called when the spin animation has finished by the callback feature of the wheel because I specified callback in the parameters.
// -------------------------------------------------------
function alertPrize()
{
// Get the segment indicated by the pointer on the wheel background which is at 0 degrees.
var winningSegment = theWheel.getIndicatedSegment();
// Do basic alert of the segment text. You would probably want to do something more interesting with this information.
// alert("You have won " + winningSegment.text);
var winText = winningSegment.text;
var winPrize = winningSegment.prize;
$.ajax({
url: '/ajax/wheeloffortune.php',
type: 'post',
data: {text:winText, prize_won:winPrize},
dataTupe: 'json',
success: function(data) {
var data = jQuery.parseJSON(data);
// Show whole array
var data2 = JSON.stringify(data);
// console.log(data2);
// De win tekst
var winText = data['tekst'];
var status = data['status'];
var likes2 = data['prize'];
var new_spins = $('.spins').text() - 1;
if(new_spins < 0) {
new_spins = 0;
}
$('.spins').html(new_spins);
$('.win_tr').show();
if(status = 'OK' && winText !== 'BAD') {
$('.winText').html('<img src="/images/icons/tick.png" /> ' + winText + '');
}else{
$('.winText').html('<img src="/images/icons/cross.png" /> Er is iets fout gegaan!');
}
wheelSpinning = false; // Reset to false to power buttons and spin can be clicked again.
},
error: function (data) {
//alert('Something went wrong');
$('.win_tr').show();
$('.winText').html('<img src="/images/icons/cross.png" /> Er is iets fout gegaan!');
wheelSpinning = false; // Reset to false to power buttons and spin can be clicked again.
}
});
}
目前没有回答
相关问题 更多 >
编程相关推荐