Selenium - 单击元素的空白区域

时间:2018-06-14 07:24:48

标签: selenium selenium-webdriver

<td width="14%" height="90" valign="top" id="cell_saturday1" name="06/02/2018" onclick="onClick(this);">
<table width="100%" height="30" id="table_saturday1"></table>
</td>

我有什么方法可以点击上面代码中 td 的任何地方,而不包含带有id table_saturday1的表格

3 个答案:

答案 0 :(得分:1)

您可以使用此Xpath点击可点击的td:

Encoding encoding = Encoding.Default;
string openSSLExe = "C:\\OpenSSL-Win32\\bin\\openssl.exe";


string unencodedPsw = "something";
string pkey = "MIIEvAIBADANB...";        //It comes from database, therefore needs to save each time.
string pwdFile = Path.GetTempFileName();
string rsaFile = Path.GetTempFileName();
string outFile = Path.GetTempFileName();

File.WriteAllBytes(pwdFile, encoding.GetBytes(unencodedPsw));
File.WriteAllBytes(rsaFile,  encoding.GetBytes(pkey));

string args = String.Format("pkeyutl -sign -in \"{0}\" -inkey \"{1}\" -out \"{2}\"", pwdFile, rsaFile, outFile);
var proc = new Process
{
    StartInfo = new ProcessStartInfo
    {
        FileName = openSSLExe,
        Arguments = args,
        UseShellExecute = false,
        RedirectStandardOutput = true,
        CreateNoWindow = true
    }
};

proc.Start();
proc.WaitForExit();

string encodedPsw = Convert.ToBase64String(File.ReadAllBytes(outFile));
File.Delete(pwdFile);
File.Delete(rsaFile);
File.Delete(outFile);

return encodedPsw;

答案 1 :(得分:1)

您可以尝试使用javascript执行程序,如下所示。

JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("document.getElementById('cell_saturday1').click();");

WebElement ele = driver.findElement(By.id("cell_saturday1"));
jse.executeScript("arguments[0].click();",ele);

或使用动作类

Actions builder = new Actions(driver);   
builder.moveToElement(ele, 0, 0).click().build().perform();

答案 2 :(得分:0)

要点击gforms_datepicker_css以外的任何地方({1}}除<td> table_saturday1 ,您可以使用以下定位策略 here

  • <table>

    id
  • cssSelector

    "td#cell_saturday1:not(#table_saturday1)"