我有一个字符串,我需要添加一个变量,所以我使用该string.format方法,但字符串也包含符号"%20"(不知道它代表什么,可能是一个空格或其他东西).无论如何,因为字符串包含多个"%",我只想将变量添加到第一个设置id,有没有办法在点或其他东西转义字符串?
就像现在一样:
ID = 12345
string.format("id=%s&x=foo=&bar=asd%20yolo%20123-1512", ID)
Run Code Online (Sandbox Code Playgroud)
我得到bad argument #3 to 'format' (no value).错误 - 因为它期望传递3个变量.
我正在尝试使用PHPUnit运行selenium测试用例.我做的第一件事是尝试登录功能,这是完美的,但我想运行一个函数来检查登录后页面上的信息,但它打开一个新的浏览器,而不是继续在当前的浏览器窗口.这是一个问题的原因是因为页面设置为在窗口关闭时删除登录身份验证,所以如果你使用$ this-> url()转到页面,它会给出我需要登录的错误.这是我的代码,它启动浏览器并运行测试登录表单的功能,然后关闭浏览器,打开一个新的并运行链接检查.这当然会因为身份验证错误而导致错误,因为窗口已关闭.我可以在一个函数中运行所有测试,但这实际上是草率编码,我想避免这种情况.有谁知道如何解决这个问题?
<?php
class TestMyTest extends PHPUnit_Extensions_Selenium2TestCase {
public function setUp()
{
$this->setBrowser("firefox");
$this->setBrowserUrl("https://**************************");
}
public function testLoginForm()
{
$this->url("login.php");
$this->byLinkText('Forgot your password?');
$form = $this->byCssSelector('form');
$this->byName('username')->value('test');
$this->byName('password')->value('1234');
$form->submit();
}
public function testCheckForMainMenueLinks ()
{
$this->url("index.php");
$this->byLinkText('Home');
$this->byLinkText('Products');
$this->byLinkText('About us');
$this->byLinkText('Contact');
}
}
?>
Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的选择元素,现在我想打开它并选择值为t3的选项,所以我尝试了这样:
<select id="selectMenu">
<option value=""> </option>
<option value="t1">test 1</option>
<option value="t2">test 2</option>
<option value="t3">test 3</option>
<option value="t4">test 4</option>
<option value="t5">test 5</option>
<option value="t6">test 6</option>
</select>
$this->byId('selectMenu')->click();
sleep(1);
$type = $this->elements($this->using('css selector')->value(option[value="t3"]'));
$type[0]->click();
Run Code Online (Sandbox Code Playgroud)
现在打开菜单,但是没有选择选项标签,我想使用select()而不是click()但是还不支持select(),或者至少是我尝试使用方法时得到的消息.我运行以下扩展PHPUnit_Extensions_Selenium2TestCase.
我想使用 WebElement 作为根来查找元素而不是驱动程序。我知道这是可能的,因为 WebElement 和 WebDriver 都扩展了 SearchContext 类。但我希望能够进行像这样的搜索。
WebDriver chromeDriver = new ChromeDriver();
WebDriver driver = chromeDriver;
// Set a new search root
public void setSearchRoot(){
if(i want a element as a root){
this.driver = (WebDriver)this.driver.findElement(By.xpath("PATH"));
}else{
this.driver = chromeDriver;
}
}
//find a element
public void findMyElement(){
this.driver.findElement(By.xpath("PATH"));
}
Run Code Online (Sandbox Code Playgroud)
而不是这样的东西
WebDriver driver = new ChromeDriver();
WebDriver rootElement = this.driver.findElement(By.xpath("PATH"));
//find a element
public void findMyElement(){
if(i want a element as a root){
this.rootElement.findElement(By.xpath("PATH"));
}else{
this.driver.findElement(By.xpath("PATH"));
}
}
Run Code Online (Sandbox Code Playgroud)
它可能看起来有点混乱,但基本上我希望能够将 …
哦,所以我对此有点困惑.我有一个看起来像这样的xml:
<track>
<artist mbid="77cceea7-91bb-4a4c-ae41-bc9c46c1ccb5"> Red Hot Chili Peppers </artist>
<name> under the bridge </name>
<streamable>0</streamable>
<mbid/>
<album mbid="0fe94139-df63-4e51-b2e7-a1d53535cdd9"> Blood Sugar Sex Magik </album>
<url> http://xxxxxx.com </url>
<date uts="1351691244">31 Oct 2012, 13:47</date>
</track>
Run Code Online (Sandbox Code Playgroud)
我使用simpleXML来解析xml,如下所示:
$artists = array();
$xml = simplexml_load_file("http://xxxxxxxxxxxxxx");
foreach($xml->recenttracks->track as $track)
{
$artist = $track->artist;
array_push($artists, $artist);
}
var_dump($artists);
Run Code Online (Sandbox Code Playgroud)
现在我希望得到一个看起来像这样的好阵列:
array(4) {
[0]=>
string(20) "Red Hot Chili Peppers "
[1]=>
string(20) "Red Hot Chili Peppers"
}
Run Code Online (Sandbox Code Playgroud)
但我得到的是这样的:
array(2)
{
[0]=> object(SimpleXMLElement)#6 (2) { ["@attributes"]=> array(1) { ["mbid"]=> string(36) "8bfac288-ccc5-448d-9573-c33ea2aa5c30" …Run Code Online (Sandbox Code Playgroud) 我需要在测试开始时最大化我的窗口,然后我找到了这个类PHPUnit_Extensions_Selenium2TestCase_Window.
所以我尝试使用这种方法,$this->maximize()但我只是得到了
BadMethodCallException:命令'maximize'不存在或不受支持.
有人知道怎么做吗?